I’m sure there’s a simple and efficient way of doing this, but for some reason I’m unable to figure out the solution. On the LHS of my rule, I’ve matched a multislot. On the RHS I’ve 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))))
There’s 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
