I agree, this is a brittle and counter-intuitive technique. Also, looking at the original problem statement:
> Please note I know about "application data", but i'd rather not use > it, because my sqrt is just a temporary value... Does storing the value in a static variable solves this? I don't know the exact semantics of Drools, but my guess is that application data is essentially the same as a static variable? Carriing over computed results from conditions/guards to the consequences/body/actions is a problem other rule engines also encounter, and I don't think it can be solved nicely (i.e. without resorting to global state) without a (small) language extension... Yours, Peter Smith, Philip wrote: > Rule firing is single threaded so that shouldn't be a problem. However, > the same static variable could be written to by the evaluation of many > conditions and as such it could be overwritten before the consequence is > actually fired. Your rules could be written such this could not happen > but this remains a brittle technique. > > Philip Smith > [EMAIL PROTECTED] > (650) 628-7941 (x87941) > > -----Original Message----- > From: sol myr [mailto:[EMAIL PROTECTED] > Sent: Tuesday, January 31, 2006 8:48 AM > To: [email protected] > Subject: Re: [drools-user] Drools: Sharing a value between the rule's > "condition" and "consequence" ? > > Thanks very much for this reply :) > However, I was wondering: will it work in a multi-threaded environment > ? > I have a Servlet, where each HTTP request is handled by a separate > thread, as usual. > All those threads use the rule engine, simultaniously... if it's a > static variable, won't they override each other's data ? > > Thanks again > Sol > > > > Ricardo Rojas Aguirre <[EMAIL PROTECTED]> wrote: > Hi, I solved the same problem with a local variable defined in the > function > tag... > > To solve your proble try somthing like this... > > > public static double sqrtResult; > > > > > > < parameter identifier="num" > > < class > Integer < / class > > < / parameter > > > < java:condition > > (sqrtResult=Math.sqrt(num.intValue())) > 1000 > < / java:condition > > > < java:consequence > > System.out.println( sqrtResult ); > < / java:consequence > > > > > Cheers > Rik > > > ----- Original Message ----- > From: "sol myr" > To: > Sent: Tuesday, January 31, 2006 11:04 AM > Subject: [drools-user] Drools: Sharing a value between the rule's > "condition" and "consequence" ? > > > >>Hi, >>I'm new to Drools. Could anyone please help with the following: >> >>Can you share data between a rule's "condition" and "consequence" ? >>For example: >>- My "condition" calculates some square root (Math.sqrt) >>- The "consequence" needs to print out the same square root >> >>It's not efficient to call Math.sqrt twice... : >> >>< parameter identifier="num" > >>< class > Integer < / class > >>< / parameter > >>< java:condition > >>Math.sqrt(num.intValue()) > 1000 >>< / java:condition > >>< java:consequence > >>System.out.println( Math.sqrt(num.intValue()) >>< / java:consequence > >> >>Is there a way to store the result of "Math.sqrt" in some temporary >>variable ( so as to avoid the duplicate calculation ) ? >>Please note I know about "application data", but i'd rather not use > > it, > >>because my sqrt is just a temporary value... >> >>Thanks :) >> >> >>--------------------------------- >> >>What are the most popular cars? Find out at Yahoo! Autos > > > > > > > > --------------------------------- > Yahoo! Autos. Looking for a sweet ride? Get pricing, reviews, & more on > new and used cars. >
