Title: Append to a list of facts

Im sure theres a simple and efficient way of doing this, but for some reason Im unable to figure out the solution.  On the LHS of my rule, Ive matched a multislot.  On the RHS Ive asserted a new fact or list of facts and want to append that to the multislot.  Something like the following:

(defrule addFacts

    ?matchedFact <- (MyTemplate (factList $?facts))

    =>

    ; Initialize the list of new facts to be appended

    (bind ?newFacts (create$))

    (while (some condition)

        ; Assert the new fact

        (bind ?newFact (assert (Template2 (slot value)))

        ; Add the new fact to the list of facts to be appended

        (bind ?newFacts (create$ ?newFacts ?newFact)))

    (modify ?matchedFact (factList create$ (?facts ?newFacts))))

Theres a lot of list creation going on here that seems very wasteful when in fact I really only have one list that I want to keep appending to.  I guess within the while loop I could use an ArrayList instead of a Jess list.  Would that be more efficient or a better practice in such a case?

Thanks for you help,

- Alan

Reply via email to