Professional Documents
Culture Documents
Advanced Pattern
Matching
(defrule black-hair-is-not-brown
(person (name ?name)(hair ~brown))
=>
(printout t ?name “ does not have brown color” crlf))
(defrule black-or-brown-hair
(person (name ?name)(hair black | brown))
=>
(printout t ?name “ does not have brown color” crlf))
(defrule neither-black-nor-brown-hair
(person (name ?name)(hair ?color&~black&~brown))
=>
(printout t ?name “ has “ ?color “ hair color” crlf))
• Example #2:
(infix) (y2 – y1) / (x2 – x1) > 0
(prefix) (> ( / ( - y2 y1 ) (- x2 x1 ) ) 0)
• (abs <numeric-expression>)
• (float <numeric-expression>)
• (integer <numeric-expression>)
(2+3)*4
CLIPS>(* (+ 2 3) 4)
20
Example:
CLIPS>(deftemplate person (slot name) (slot salary))
CLIPS>(assert (person (name “ali”) (salary (+ 300 400))))
CLIPS>(watch rules)
CLIPS>(watch activations)
CLIPS>(watch facts)
CLIPS>(reset)
CLIPS>(run)
%-M.Nx
(test <predicate-function>)
Example:
(test (> ?value 1))
(deftemplate fire-squad
(slot name
(slot location))
(deftemplate evacuated
(slot building))
• For every fact that matches the (emergency (type fire) (location ?
where)) pattern, there must also be facts matching the (fire-
squad (location ?where)) pattern and the (evacuated (building ?
where)) pattern.