It -would- often be more efficient to call the function ahead of
time, but it's not so easy to find a way to cache the value during
matching. In the case of a no-argument function, or one with arguments
that don't depend on the matching process, you could do this: write a
function (deffunction or Java Userfunction) which maintains a
Hashtable with OBJECTs as the keys, and the results of calling
someFunction as the elements. Then in the rule, you call the function,
which looks up the object and either calls someFunction or not,
and returns the result.

Of course, it opnly makes sense to do this if someFunction consumes a
nonzero amount of CPU, so you might want to benchmark first!


I think [EMAIL PROTECTED] wrote:
> 
> 
> I find myself continually trying to extract values from my Jess
> instances and using them during pattern matching.  I write rules that
> look like this:
> 
> (defrule example
>       ?foo <- (foo (id ?id) (OBJECT ?fooObject))
>       (bind ?val (call ?fooObject someFunction))
>       ?bar <- (bar ?val)
>       =>
>       (retract ?bar)) 
> 
> Of course, such rules don't work.  
> 
> I realize I could do 
>       ?bar <- (bar ?val&=(call ?fooObject someFunction))
> 
> It seems like it would be more efficient to compute the value of ?val
> first before matching, but maybe I don't have to worry about that?
> 
> In a nutshell: is there a correct way to establish bindings on the LHS
> other than by pattern matching?
> 
> (BTW I'm still using Jess 4.4 if it makes a difference.  Am planning
> to upgrade when this week's demo deadline is past. 8-o )
> 
> -- 
> 
> robin
> =:-{)
> University of California, Irvine
> Information and Computer Science Dept.
> 
> http://www.ics.uci.edu/~burke/
> 
> "The universe is made of stories, not of atoms" - Muriel Rukeyser
> ---------------------------------------------------------------------
> 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