I think Vadim Zaliva wrote:
>
> On Mon, 9 Aug 1999, Ernest Friedman-Hill wrote:
>
> > This is a very frequently asked question (I supposed it should be a
> > FAQ entry) by folks just getting started in rule-based languages. The
> > reason the solution isn't obvious is because you're thinking about it
> > in procedural-programming terms, which isn't appropriate for a
> > rule-based language. Instead of trying to create a list of facts with
> > some property and then iterating over the list, you should write a
> > rule which operates on one fact based on some criteria.
> >
> > (defrule init
> > =>
> > (store HELPER (new Helper)))
> >
> > (defrule one-fact
> > (f (v ?x))
> > =>
> > (call (fetch HELPER) addSlotVValue ?x))
> > )
> >
> > Instead of using a custom "Helper" object for this, you might use the
> > Jess "bag" function, which is really just a Jess language interface to
> > java.util.Hashtable.
>
> I thought about approach you've proposed. It will work if I need this rule
> fired only once. What if I need it to be fired several times? I need
> helper to be initialized before first fact added, and some method of it
> fired after last fact added to it. In my case Helper is not just
> container, it is doing some processing.
>
The above rule one-fact is intended to fire multiple times, once for
each "f" fact, so you're all set there. If you want another rule to
fire after one-fact has fired for each "f" fact, you have many
choices: use salience to make the second rule a lower priority;
retract each "f" fact as it is processed and have the second rule
matchg (not (f)); modify each "f" fact and have the second rule fire
when no unmodified facts exist; etc.
The "init" rule will definitely fire before one-fact ever fires.
> Sincerely,
> Vadim
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------