Search code examples
jess

removing a multislot variable in JESS


I have a deftemplate which contains a multislot in JESS and I want to delete a variable in the multilot if the rule is fired. for example:

(deftemplate Person (slot name)
                    (multislot friends))
(assert (Person (name John)(friends Jimmy Joe Jessica)))

now i want to delete Jimmy from the friends slot.

Thank you very much Ali


Solution

  • I've fixed some omissions in your question, assuming that the template name is Person.

    This rule eliminates Jimmy from all friends of all Persons.

    (defrule KillJimmy
        ?p <- (Person (friends $?a Jimmy $?b))
    =>
        (modify ?p (friends (create$ $?a $?b)))
    )