Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

CLIPS – compare 2 facts if are equal, with wildcard in rule

I am trying to create rule which compares in this way:

CLIPS> (assert (flower red yellow))
CLIPS> (assert (flower blue yellow))
CLIPS> (assert (isflower yellow))
CLIPS> (defrule has_color2
(isflower ?x)
(eq flower red ?x flower red ?)
=>
(printout t "has property" ?x crlf))
CLIPS> (run)

So my question is this ; How to compare a variable against a set of facts to check if theres any match ? The alone ? mark on the 6th line is where I want to insert a wildcard in a way it’s done. Whole line is inaccurate probably.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

CLIPS> (assert (flower red yellow))
<Fact-1>
CLIPS> (assert (flower blue yellow))
<Fact-2>
CLIPS> (assert (isflower yellow))
<Fact-3>
CLIPS> 
(defrule has_color2
   (isflower ?x)
   (flower ? ?x)
   =>
   (printout t "has property " ?x crlf))
CLIPS> (agenda)
0      has_color2: f-3,f-2
0      has_color2: f-3,f-1
For a total of 2 activations.
CLIPS> (facts)
f-1     (flower red yellow)
f-2     (flower blue yellow)
f-3     (isflower yellow)
For a total of 3 facts.
CLIPS> (run)
has property yellow
has property yellow
CLIPS> 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading