Menu

enumerated type

Help
Liuba3
2012-03-28
2012-11-23
  • Liuba3

    Liuba3 - 2012-03-28

    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?

     
  • Gary Riley

    Gary Riley - 2012-04-13

    You can store an instance in a fact slot, so it's certainly possible.

    CLIPS> 
    (defclass ENUM-TYPE (is-a USER)
       (multislot values))
    CLIPS>    
    (defmessage-handler ENUM-TYPE enum-index (?v)
       (member$ ?v ?self:values))
    CLIPS>    
    (defmessage-handler ENUM-TYPE index-value (?i)
       (nth$ ?i ?self:values))
    CLIPS> (make-instance [colors] of ENUM-TYPE (values red green blue))
    [colors]
    CLIPS> (send [colors] enum-index green)
    2
    CLIPS> (send [colors] index-value 3)
    blue
    CLIPS>
    
     

Log in to post a comment.