That too creates a new list.  I was hoping to just append to an existing list.

 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dusan Sormaz
Sent: Wednesday, September 27, 2006 10:33 AM
To: [email protected]
Subject: Re: JESS: Append to a list of facts

 

I thought that Ernest would give an answer :-).

Could insert work (from reference):

(insert$ <list-_expression_> <integer-_expression_> <single-or-list-_expression_>+)

Arguments:

A list, an integer, and one or more lists

Returns:

A list

Description:

Returns a new list like the original but with one or more values inserted. Inserts the elements of the second and later lists so that they appear starting at the given 1-based index of the first list.

Dusan Sormaz

At 04:32 PM 9/26/2006, you wrote:


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

*********************************************************************
*
Dusan SormazPhD, Associate Professor
* Ohio University
* Industrial and Manufacturing Systems Engineering Department
* 277 Stocker Center, Athens, OH 45701-2979
* phone: (740) 593-1545
* fax:   (740) 593-0778
* e-mail: [EMAIL PROTECTED]
* url: http://www.ent.ohiou.edu/~sormaz
*********************************************************************

Reply via email to