n00b defrule problem

21 views
Skip to first unread message

martin

unread,
May 8, 2011, 7:31:55 AM5/8/11
to CLIPSESG
For my first self written defrule I thought I try some classic prolog
family example, but I must mess up somewhere. What am I doing wrong?

(deffacts startup
(father-son adam kain)
(father-son adam abel)
(mother-son eva kain)
(mother-son eva abel)
)

(defrule brothers
(father-son ?father ?son)
(father-son ?father2 ?son2)
(mother-son ?mother ?son)
(mother-son ?mother2 ?son2)
(neq ?son ?son2)
(eq ?father ?father2)
(eq ?mother ?mother2)
=>
(assert (brothers ?son ?son2))
(printout t "new fact: " ?son " and " ?son2 " are brothers."))

(reset)
(run)

P.S. Love CLIPS up until now.

baylor wetzel

unread,
May 8, 2011, 11:33:27 AM5/8/11
to clip...@googlegroups.com, martin
i'm sure someone else will try this and find the precise problem but off the top of my head i don't think you can do  (eq f1 f2), you'd do (test (eq f1 f2)) although you shouldn't do that either, you should use the same variable name in both places

(defrule brothers
       (father-son ?f ?son)
       (father-son ?f ?son2)
       (mother-son ?m ?son)
       (mother-son ?m ?son2)
       (test (neq ?son ?son2))
=>


-baylor


--
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To post to this group, send email to CLIP...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en

--> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Click on "Edit my membership" link.
Select the "No Email" radio button.
Click the "Save these settings" button.

--> IF YOU WANT TO UNSUBSCRIBE <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Sign in
Click on "Edit my membership" link.
Click the "Unsubscribe" button.
Note: This appears to be the most reliable way to unsubscribe

Alternately, send email to CLIPSESG-u...@googlegroups.com. You will receive an email which you must respond to as well to unsubscribe. Clicking the link mentioned in the unsubscribe reply does not appear to work reliably.

CLIPS Support

unread,
May 8, 2011, 11:40:05 AM5/8/11
to CLIPSESG
Three different ways to rewrite the rule:

(defrule brothers
(father-son ?father ?son)
(father-son ?father2 ?son2)
(mother-son ?mother ?son)
(mother-son ?mother2 ?son2)
(test (neq ?son ?son2))
(test (eq ?father ?father2))
(test (eq ?mother ?mother2))
=>
(assert (brothers ?son ?son2))
(printout t "new fact: " ?son " and " ?son2 " are brothers."
crlf))

(defrule brothers
(father-son ?father ?son)
(father-son ?father2 ?son2)
(mother-son ?mother ?son)
(mother-son ?mother2 ?son2)
(test (and (neq ?son ?son2)
(eq ?father ?father2)
(eq ?mother ?mother2)))
=>
(assert (brothers ?son ?son2))
(printout t "new fact: " ?son " and " ?son2 " are brothers."
crlf))

(defrule brothers
(father-son ?father ?son)
(father-son ?father ?son2&~?son)
(mother-son ?mother ?son)
(mother-son ?mother ?son2)
=>
(assert (brothers ?son ?son2))
(printout t "new fact: " ?son " and " ?son2 " are brothers."
crlf))
Reply all
Reply to author
Forward
0 new messages