Hi Vadim,

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 think Vadim Zaliva wrote:
> 
> Hi!
> 
> I am new to CLIPS.
> 
> Here is problem I am trying to solve now.
> I have several facts. For example:
> 
> (f (v 1))
> (f (v 2))
> (f (v 7))
> 
> now I need to write rule, which will have multifield
> containing slot 'v' value of all matching facts.
> 
> (defrule all-facts
>       ??????
> =>
>  (bind ?helper (new Helper))
>  (foreach ?i $?all
>            (call ?helper addFact ?i))
> )
> 
> As I see I need to feed them to some Helper object.
> 
> Maybe there is some other way doing it? If no, how could I create such
> multifield. Also, I do not want to retrat facts while the rule is execute,
> I will need them later.
> 
> Any advice is appreciated.
> 
> Thanks!
> 
> Vadim
> 
> -- 
> ;;-----------------------------------+-----------------------------------+
> ;; [EMAIL PROTECTED]      + Those who do not understand Unix  +
> ;; Project Manager, Matranet Inc.    + are condemned to reinvent it,     +
> ;; http://www.matranet.com/          + poorly.          (H. Spencer)     +
> ;;-----------------------------------+-----------------------------------+
> 
> 
> ---------------------------------------------------------------------
> 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 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 (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to