Try this: (deftemplate Person (slot Name (type STRING)) (multislot Ancestors) )
(assert (Person (Name "a") (Ancestors (assert (Person (Name "b"))) (assert (Person (Name "c"))) ) ) ) (defrule removePersonReferences (remove-person ?name) ?person <- (Person (Name ?name)) ?decendent <- (Person (Ancestors $?pre ?person $?post)) => (modify ?decendent (Ancestors (create$ ?pre ?post)) ) ) (defrule removePerson ?trigger <- (remove-person ?name) ?person <- (Person (Name ?name)) (not (Person (Ancestors $?pre ?person $?post))) => (retract ?person) (retract ?trigger) ) Output from run: Jess> (watch all) TRUE Jess> (batch "..\\test2.jess") ==> f-0 (MAIN::Person (Name "b") (Ancestors )) ==> f-1 (MAIN::Person (Name "c") (Ancestors )) ==> f-2 (MAIN::Person (Name "a") (Ancestors <Fact-0> <Fact-1>)) MAIN::removePersonReferences: +1+1+1+1+2+1+2+t MAIN::removePerson: =1=1=1=1=2=1+2+t TRUE Jess> (assert (remove-person "c")) ==> f-3 (MAIN::remove-person "c") ==> Activation: MAIN::removePersonReferences : f-3, f-1, f-2 <Fact-3> Jess> (run) FIRE 1 MAIN::removePersonReferences f-3, f-1, f-2 ==> Activation: MAIN::removePerson : f-3, f-1, <=> f-2 (MAIN::Person (Name "a") (Ancestors <Fact-0>)) FIRE 2 MAIN::removePerson f-3, f-1, <== f-1 (MAIN::Person (Name "c") (Ancestors )) <== f-3 (MAIN::remove-person "c") 2 Jess> (facts) f-0 (MAIN::Person (Name "b") (Ancestors )) f-2 (MAIN::Person (Name "a") (Ancestors <Fact-0>)) For a total of 2 facts. Jess> You will have to arrange to have one of your rules assert the (remove-person) fact. Also, you could use a defquery to find all related (Person) facts that reference to-be-removed person fact and then modify each of the returned facts and their Ancestor multifields. Good luck! alan > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of portalguy > Sent: Wednesday, June 29, 2005 10:01 AM > To: jess-users@sandia.gov > Subject: JESS: Remove all references pointing to the > retracted fact from the slots > > > Hi, > I'm trying to find the quickest way to setting references in > slots to a retracted fact to nil or remove them if in a > multislot. For instance if I have the following template: > > (deftemplate Person > (slot Name (type STRING)) > (multislot Ancestors) > ) > > and the following facts: > > (assert > (Person (Name "a") > (Ancestors (assert (Person (Name "b"))) > (assert (Person (Name "c"))) > ) > ) > ) > > f-0 (MAIN::initial-fact) > f-1 (MAIN::Person (Name "b") (Ancestors )) > f-2 (MAIN::Person (Name "c") (Ancestors )) > f-3 (MAIN::Person (Name "a") (Ancestors <Fact-1> <Fact-2>)) > For a total of 4 facts in module MAIN. > > Now if I remove say fact 1 I need to remove it from ancestors > in fact 3 but if I only do (retract 1) I end up with the > following and as you can see fact 3 still hold reference to > none existing fact 1: > f-0 (MAIN::initial-fact) > f-2 (MAIN::Person (Name "c") (Ancestors )) > f-3 (MAIN::Person (Name "a") (Ancestors <Fact-1> <Fact-2>)) > For a total of 3 facts in module MAIN. > > The question is what is the quickest way to clean up the > reference issue, other than going through every slot and > verifying that it is not pointing to a none existing fact. > > Thanks > > -------------------------------------------------------------------- > 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] --------------------------------------------------------------------