[rules-users] Binding mysteries

Sonata plz.write.to at gmail.com
Thu Nov 28 22:16:49 EST 2013


Hi, got a few questions about binding variables, hope someone can help out,
thanks.

1. Does binding actually cache the result for the RHS?
example:
rule "no binding"
when c : MyClass(member1 != member2)
then c.somemethod(imp.getMember1());
end

rule "with binding"
when c : MyClass(m : member1, member1 != member2)
then c.somemethod(m);
end

Does "no binding" call getMember1() twice while "with binding" calls
getMember1() once and cache the result to m? Or are both the same?

2. Is the practice to bind before or after?
example
rule "binding after"
when c : MyClass(member1 != member2, m : member1)
then c.somemethod(m);
end

Is there any difference between "with binding" and "binding after"?

3. Is bind and use in the LHS any better?
example
rule "binding and use"
when c : MyClass(m : member1, m != member2)
then c.somemethod(m);
end

Is there any difference between "with binding" and "binding and use"?

4. Why binding with constraint is not recommended?
example
rule "binding with constraint"
when c : MyClass(m : member1 != member2)
then c.somemethod(m);
end

In the expert manual, Drools 5.5.0 section 4.8.3.3.5. Binding variables, it
said
// Not recommended
Person( $age : age * 2 < 100 )
// Recommended (separates bindings and constraint expressions)
Person( age * 2 < 100, $age : age )

Although I know $age : age * 2 < 100 is binding $age to age *ONLY*, while
$age : (age * 2 < 100) is binding $age to the result of (age * 2 < 100). Is
the recommendation only about this safety precaution?

Thank you so much for answering.



--
View this message in context: http://drools.46999.n3.nabble.com/Binding-mysteries-tp4026999.html
Sent from the Drools: User forum mailing list archive at Nabble.com.


More information about the rules-users mailing list