I need to use several templates cntaining enumerated fields (inherited from C program). How can I implement this type in CLIPS? Is it possible to define a generic ENUM-TYPE class that, given the enumerate int value, returns the consistent string value, and vice versa?
You can store an instance in a fact slot, so it's certainly possible.
(defclass ENUM-TYPE (is-a USER)
(defmessage-handler ENUM-TYPE enum-index (?v)
(member$ ?v ?self:values))
(defmessage-handler ENUM-TYPE index-value (?i)
(nth$ ?i ?self:values))
CLIPS> (make-instance [colors] of ENUM-TYPE (values red green blue))
CLIPS> (send [colors] enum-index green)
CLIPS> (send [colors] index-value 3)
Sign up for the SourceForge newsletter:
You seem to have CSS turned off.
Please don't fill out this field.