'clips how to make rule match forall but one

How could i make a rule that test if all facts from a deftemplate but one matches an specific condition?

Example: with

(deftemplate person (field name)(field hair-color))

having several blonde people, only one is not

get

(printout t "Only " ?name-not-blond " is not blonde" crlf)


Solution 1:[1]

         CLIPS (6.4 2/9/21)
CLIPS> 
(deftemplate person
   (slot name)
   (slot hair-color))
CLIPS>  
(defrule only-one-not-blonde
   (person (name ?name-not-blonde)
           (hair-color ~blonde))
   (not (person (name ~?name-not-blonde)
                (hair-color ~blonde)))
   =>
   (println "Only " ?name-not-blonde " is not blonde."))
CLIPS>         
(deffacts initial
   (person (name Sue) (hair-color blonde))
   (person (name Frank) (hair-color blonde))
   (person (name Josh) (hair-color brown)))
CLIPS> (reset)
CLIPS> (facts)
f-1     (person (name Sue) (hair-color blonde))
f-2     (person (name Frank) (hair-color blonde))
f-3     (person (name Josh) (hair-color brown))
For a total of 3 facts.
CLIPS> (agenda)
0      only-one-not-blonde: f-3,*
For a total of 1 activation.
CLIPS> (assert (person (name Anne) (hair-color red)))
<Fact-4>
CLIPS> (agenda)
CLIPS> 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Gary Riley