This is the trditional CLIPS solution, but it involves lots, lots more
computational work (both in CLIPS and in Jess.) If the number of
"purchase" facts is N, then roughly 2(N^2) partial matches will be
formed.  The total number of rule activations is almost as large. The
defquery solution forms only N partial matches. If N is 50, 2(N^2) is
5000, so the traditional solution does ~100 times more computation
(actually worse since all the activations have to be processed and the
rule has to fire ~50 times.) Plus, as you say, it's destructive.

Defqueries are a Good Thing for applications like this.

I think Thomas Gentsch wrote:
> 
> I would have done something like that:
> 
> (defrule sum
>   ?f1 <- (purchase ?s1)
>   ?f2 <- (purchase ?s2)
>          (test (neq ?f1 ?f2))
> =>
>   (retract ?f1)
>   (retract ?f2)
>   (assert (purchase (+ ?s1 ?s2)))
> )
> 
> Works at least with CLIPS but I suppose with Jess as well. How does that
> compare performance-wise?
> 
> (Of course, your initial facts are gone afterwards - if you want to keep
> them, it gets a little more difficult).
> 
>       tge
> 
> [EMAIL PROTECTED] wrote:
> > 
> > The most efficient way to do it would be to use a defquery to find all
> > the PURCHASE facts, then iterate over the query result directly and
> > add them up. You could define a deffunction to do this.
> > 
> > I think John Goalby wrote:
> > > I would like to be able to have the following facts...
> > >
> > > (assert (PURCHASE 100))
> > > (assert (PURCHASE 150))
> > > (assert (PURCHASE 70))
> > >
> > > and then be able to have a rule that would give me the
> > > sum of these purchases.  Is that possible?
> > >
> > > Thanks
> > >
> > > John.
> > 
> 
> -- 
>     Thomas Gentsch
> 
> 
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
> 



---------------------------------------------------------
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]
---------------------------------------------------------------------

Reply via email to