I'm playing on jess. I want to make rule that is not using '~'.
Here is my code.
(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)
What I expected was variable ?hair is not brown.
Note that the function
(not ...)
negates its argument. TRUE is true, FALSE is false, and any other symbol is true.To test whether a slot value is equal or not equal to some value, use
(eq ...)
or(neq ...)
or(= ...)
or(<> ...)
.Result:
Direct matching is, of course, preferable.