Hello,
Is it possible to write a rule that specifies two objects hold on to
each other?
When saving the following snippet, the Eclipse IDE complains <<Unable
to return Declaration for identifier 'a'>>:
rule "purple-eyed_ozies"
when
p : Person(eye_color == "purple", nm : name, address == a )
a : Address( person == p, country == "oz")
then
System.out.println( "Found purple-eyed ozian: "+nm );
end
If I can avoid it, I would rather not use keys or object ids to
implement the association or link. For whatever it may be worth, I am
trying to duplicate the following experiment that works in JESS:
(deftemplate person (slot name) (slot eye_color) (slot address) )
(deftemplate address (slot person) (slot street) (slot city) (slot
zip) (slot country) )
(deffunction people ()
(bind ?p (assert(person (name rincewind) (eye_color octarine))))
(bind ?a (assert(address (country klatch) (person ?p))))
; Yes, when we break the bidirectional relationship
; by commenting out the next line, rincewind is no longer found.
(modify ?p (address ?a))
(bind ?p (assert(person (name atuin) (eye_color purple))))
(bind ?a (assert(address (country klatch) (person ?p))))
(modify ?p (address ?a))
(bind ?p (assert(person (name barney) (eye_color purple))))
(bind ?a (assert(address (country oz) (person ?p))))
(modify ?p (address ?a))
(bind ?p (assert(person (name scarecrow) (eye_color octarine))))
(bind ?a (assert(address (country oz) (person ?p))))
(modify ?p (address ?a))
)
(defrule purple-eyed_ozies
?p <- (person (eye_color purple) (name ?nm) (address ?a))
?a <- (address (person ?p) (country oz))
=>
(printout t "Found purple-eyed ozian: " ?nm "
"))
(defrule octarine-eyed_klatchians
?a <- (address (country klatch) (person ?p))
?p <- (person (eye_color octarine) (name ?nm) (address ?a))
=>
(printout t "Found octarine-eyed klatchian: " ?nm "
"))
(people)
(run)
(exit)
Thank you,
Art
Show replies by date