You just need to store them somewhere while you add them up. You could
use a fact, or, as I've done here, use a
defglobal. combine-all-facts-1 will fire once for each 'a'
fact. combine-all-facts-2 will fire after all combine-all-facts-1
activations have fired.

(defglobal ?*all-as* = (create$))
(defrule combine-all-facts-1
   (a ?X)
   =>
   (bind ?*all-as (create$ ?X ?*all-as*)))

(defrule combine-all-facts-2
   ;; don't run until the other rule is finished
   (declare (salience -1))
   =>
   (assert (A ?*all-as*)))

You could avoid using salience if you could retract each 'a' as it was
counted; then just make the second rule fire on (not (a)).


I think S Yang wrote:
> 
> Thanks for the prompt reply. However, the answer 
> works only if the number of facts to be combined
> is known. The problem I am facing is that the 
> facts are all in the form of (a ...), but I don't
> know how many in advance. I just need to combine 
> them all.
> 
> Thanks again for the help.
> 
> Sam Yang
> 
> At 07:15 15/04/99 -0700, you wrote:
> >(defrule combine-facts
> >     (a ?X)
> >     (a ?Y&~?X)
> >     (a ?Z&~Y&~X)
> >     =>
> >     (assert (A ?X ?Y ?Z)))
> >
> >Something like that?
> >
> >
> >I think S Yang wrote:
> >> 
> >> Dear All,
> >> 
> >> I am trying to write some JESS programs. It is easy to 
> >> start but to write something useful, it is much more 
> >> difficult than other languages. One of the problwm I 
> >> often face can be simplified as the following:
> >> 
> >> Given a list of facts:
> >>  (a 1)
> >>  (a 2)
> >>  (a 3)
> >> ...
> >> 
> >> How do you construct a fact?
> >>  (A 1 2 3 ...)
> >> 
> >> Thanks in advance.
> >> 
> >> Sam Yang
> >> 
> >> 
> >> ---------------------------------------------------------------------
> >> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> >> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> >> list. 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 9214                  [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. List problems? Notify [EMAIL PROTECTED]
> >---------------------------------------------------------------------
> > 
> 
> ---------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
> in the BODY of a message to [EMAIL PROTECTED], NOT to the
> list. 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 9214                  [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. List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to