tags:

views:

175

answers:

3

Hello,

I'd like to declare a global variable that is scoped to only my rules file. For example: variable $reUseMe is only declared once.

rule 1

$reUseMe : POJO(val = 1) //other conditions

rule 2

$reUseMe > val

A: 

I'll just insert it into the working memory. Was trying not to do this.

Andy
+2  A: 

you can refer to globals in LHS via eval:

global SomeType variable

rule ... when ... eval(variable > something)

Michael Neale
+1  A: 

There are no scoped global variables, but in some cases rule inheritance helps.

rule "Rule 1"
  when
    $reUseMe :POJO( val == 1 )
  then
end

rule "Rule 2" extends "Rule 1"
  when
    # You can use the variables from Rule 1
    POJO( val > $reUseMe.val ) 
  then
end

Only LHS is added. RHS from Rule 1 is ignored in Rule 2.

Toni Rikkola
This is helpful. Could you share a link to any documentation on this?Thanks!
Andy
I could only find this blog entry, check "category rules" http://blog.athico.com/2008/10/while-everyone-was-having-fun-at-orf.htmlThat is how it is used in Guvnor, but in DRL you use it like in my example, what it does is it copies the condition of Rule 1 on top of Rule 2. This way you can use all the variables and conditions you had in Rule 1 in Rule 2.
Toni Rikkola