1
votes

I am trying to write a rule that will match when a certain value is not in a multislot, and then add that value to it.

(deftemplate person
    (multislot packing_list
    (type SYMBOL)
    (default ?DERIVE)))

(defrule apply_adapter
    (travel international)
    ?p <- (person (packing_list $? ~travel_adaptor ))
    =>
    (modify ?p (packing_list travel_adaptor)))
    (println "Added to list" crlf)
)

(deffacts start
    (travel international)
    (person)
)

Two parts of this I know aren't correct:

  1. ?p <- (person (packing_list $? ~travel_adaptor )) does not fire the rule - what is the correct syntax?
  2. (modify ?p (packing_list travel_adaptor))) probably does not do what I want, which is to insert the value, not replace the list.

Any ideas how to fix this?

1

1 Answers

2
votes
         CLIPS (Cypher Beta 8/21/18)
CLIPS> 
(deftemplate person
   (multislot packing_list
      (type SYMBOL)
      (default ?DERIVE)))
CLIPS> 
(defrule apply_adapter
   (travel international)
   ?p <- (person (packing_list $?pl))
   (test (not (member$ travel_adaptor ?pl)))
   =>
   (modify ?p (packing_list ?pl travel_adaptor))
   (println "Added to list"))
CLIPS> 
(deffacts start
   (travel international)
   (person))
CLIPS> (reset)
CLIPS> (run)
Added to list
CLIPS> (facts)
f-1     (travel international)
f-2     (person (packing_list travel_adaptor))
For a total of 2 facts.
CLIPS>