Menu

Modify a fact using a variable like slot name

Help
pron
2012-01-10
2012-11-23
  • pron

    pron - 2012-01-10

    Is it possible to modify the fact "?u" using a variable like the slot name, instead of a symbol?

    (defrule R-1
         ?u <- (user)
         ?f <-  (question
                     (answered no)
                     (the-question ?q)
                     (attribute ?attribute))
         =>
         (modify ?f (answered yes))
         (modify ?u (?attribute 5))
    )

     
  • Gary Riley

    Gary Riley - 2012-04-17

    You can't do this with facts, but you can with instances since the message argument to the send function can be a constant, variable, or expression.

    CLIPS> 
    (defclass EXAMPLE (is-a USER)
       (slot x)
       (slot y)
       (slot z))
    CLIPS> (make-instance [x] of EXAMPLE (x 1) (y 2) (z 3))
    [x]
    CLIPS> (send [x] print)
    [x] of EXAMPLE
    (x 1)
    (y 2)
    (z 3)
    CLIPS> (send [x] (sym-cat put- x) 5)
    5
    CLIPS> (send [x] print)
    [x] of EXAMPLE
    (x 5)
    (y 2)
    (z 3)
    CLIPS>
    
     

Log in to post a comment.