I think that Ross Judson said: >>At this point I would like fact 2 to be retracted...I can't quite see how to get there.
Hi Ross, One obvious problem is that you have a logic error in your rule. You have the ?id variable being bound to the return value of the member$ function. Quoting the Jess function reference: "Returns the position (1-based index) of a single-field value within a multifield value; otherwise, returns FALSE." You are expecting it to return the id value, which it's not -- it won't necessarily correspond to the slot value. Also, you need to do a (reset) before you run Jess so that the (MAIN::initial-fact) gets asserted, or Jess won't run properly. Make sure that you do it before your assertions, else reset will wipe them out. Using (deffacts) is a convenient way to load a bunch of facts at once when you do the (reset). Cheers, Jason FYI/BTW - Another tricky point that Ernest has pointed out before is that LISP dialects treat anything else than a FALSE as TRUE, so the integer return value of member$ can be used in boolean expressions as is. ------------------------ Jason Morris Morris Technical Solutions [EMAIL PROTECTED] www.morristechnicalsolutions.com fax/phone: 503.692.1088 > -----Original Message----- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > Behalf Of Judson, Ross > Sent: Monday, August 09, 2004 11:14 AM > To: [EMAIL PROTECTED] > Subject: JESS: Multifield matching > > > Let's say I have two deftemplates: > > (deftemplate obj (slot id)) > (deftemplate dep (multislot depends-on)) > > The depends-on multislot contains the ids of obj facts that the dep fact > needs to exist. If _any_ of the obj facts are missing, I want to > retract the dep fact. Writing a rule for this is perplexing me :) . > > (defrule prune > ?f <- (dep (depends-on $?targets)) > (not (obj (id ?id&:(member$ ?id $?targets)))) > => > (retract ?f)) > > This doesn't work, and I really didn't think it would. Consider: > > Jess> (deftemplate obj (slot id)) > TRUE > Jess> (deftemplate dep (multislot targets)) > TRUE > Jess> (defrule prune > ?f <- (dep (targets $?targets)) > (not (obj (id ?id&:(member$ ?id $?targets)))) > => > (retract ?f)) > TRUE > Jess> (assert (obj (id ross))) > <Fact-0> > Jess> (assert (obj (id judson))) > <Fact-1> > Jess> (agenda) > For a total of 0 activations. > Jess> (assert (dep (targets ross judson))) > <Fact-2> > Jess> (agenda) > For a total of 0 activations. > Jess> (assert (dep (targets ross nowhere))) > <Fact-3> > Jess> (agenda) > For a total of 0 activations. > Jess> (assert (dep (targets nowhere))) > <Fact-4> > Jess> (agenda) > [Activation: MAIN::prune f-4, ; time=5 ; salience=0] > For a total of 1 activations. > Jess> (run) > 1 > Jess> (retract 0) > TRUE > Jess> (agenda) > [Activation: MAIN::prune f-3, ; time=7 ; salience=0] > For a total of 1 activations. > Jess> (run) > 1 > Jess> (facts) > f-1 (MAIN::obj (id judson)) > f-2 (MAIN::dep (targets ross judson)) > For a total of 2 facts. > Jess> > > At this point I would like fact 2 to be retracted...I can't quite see > how to get there. The forall example seems like it might be headed in > the right direction, but not quite... > > Ross Judson > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' > in the BODY of a message to [EMAIL PROTECTED], NOT to the list > (use your own address!) List problems? Notify [EMAIL PROTECTED] > -------------------------------------------------------------------- > -------------------------------------------------------------------- To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' in the BODY of a message to [EMAIL PROTECTED], NOT to the list (use your own address!) List problems? Notify [EMAIL PROTECTED] --------------------------------------------------------------------