CLIPS:值不在多槽中时匹配

时间:2018-09-26 13:05:56

标签: clips

我正在尝试编写一个规则,该规则在某个值不在多槽位中时会匹配,然后将该值添加到其中。

(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)
)

我知道这两个部分是不正确的:

  1. ?p <- (person (packing_list $? ~travel_adaptor ))不会触发规则-正确的语法是什么?
  2. (modify ?p (packing_list travel_adaptor)))可能不满足我的要求,即插入值,而不是替换列表。

有什么办法解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

         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>