我在jess上玩。我想制定不使用'〜'。
的规则这是我的代码。
(clear)
(reset)
(deftemplate person
(slot name)
(slot eyes)
(slot hair))
(defrule person-without-brown-hair
(person (name ?name) (hair ?hair&:(not brown)))
=>
(printout t ?name " does not have brown hair." crlf))
(assert (person (name "Jeon") (eyes green) (hair brown)))
(assert (person (name "Park") (eyes blue) (hair red)))
(run)
我的预期是多变的?头发不是棕色的。
答案 0 :(得分:2)
请注意,函数(not ...)
否定了它的参数。 TRUE为true,FALSE为false,任何其他符号为true。
要测试广告位值是否等于某个值,请使用(eq ...)
或(neq ...)
或(= ...)
或(<> ...)
。
(defrule person-without-brown-hair
(person (name ?name) (hair ?hair&:(neq ?hair brown)))
=>
(printout t ?name " does not have brown hair." crlf))
结果:
Park does not have brown hair.
1
直接匹配当然更可取。