RE: [rules-users] single binding for or CE flagged by compiler

2009-03-16 Thread Hehl, Thomas
Not getting into whether this is a bad practice, the only language I've
ever seen support this syntax is COBOL. Every other language I've worked
in (and there are many) do not support this technique, so it seems
reasonable that this syntax should be disallowed in drools as well.

 



From: rules-users-boun...@lists.jboss.org
[mailto:rules-users-boun...@lists.jboss.org] On Behalf Of Edson Tirelli
Sent: Monday, March 16, 2009 9:58 AM
To: Rules Users List
Subject: Re: [rules-users] single binding for or CE flagged by compiler

 


   This is an old discussion. Single binding on or is a non-orthogonal
special case on the language syntax that was introduced in the early
days when we only had infix CEs. When we started to support prefix CE,
the special case was not updated, and as a result, the single binding
works only with infix.

   IMO, this syntax promotes bad practices and should be disallowed.
Although, some people like it and it is still in there. Just to clarify
why I think it promotes bad practice:

* When you have the same object type for all the patterns inside an or
group, you should be using constraint connector ||, not the or CE.
Using your example:

$t : Trigger( fa == 1 || == 2 ) // or any variation of the syntax.

   This keeps the network smaller and prevents unexpected behavior when
the constraints are not mutually exclusive and in some cases people
forget that the rule will fire once for each logical branch when using
or.

* If the object types are different, then you can't use single binding
anyway:

$o  : ( Cheese() or Wine() ) // this will lead to ClassCastExceptions on
the usage of $o.

   So, I really think that the single binding or fulfilled its purpose
on Drools 3, when we didn't had all the flexibility in the language we
have today. But now, the only thing it achieves is promoting bad
practices.

   Just my 0.02c.

   []s
   Edson

2009/3/16 Wolfgang Laun wolfgang.l...@gmail.com

As far as I know, this should work:

package orel;
import orel.Main.Trigger;
rule ror1
when
$t : (or Trigger(fa == 1)
 Trigger(fa == 2))
then
System.out.println( fired  + $t.getName() );
end

This is what Drools-5.0.0 kbuilder.getErrors().toString() returns:

[5,11]: [ERR 102] Line 5:11 mismatched input 'Trigger' expecting '(' in
rule ror1 in pattern or[6,14]: [ERR 102] Line 6:14 mismatched input
'Trigger' expecting ')' in rule ror1[6,30]: [ERR 102] Line 6:30
mismatched input ')' expecting 'then' in rule ror1

Shouldn't toString() insert line ends? As it is, the result is pretty
much useless.

This works:
rule ror1
when
(or $t : Trigger(fa == 1)
$t : Trigger(fa == 2))
then
System.out.println( fired  + $t.getName() );
end

-W


___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss, a division of Red Hat @ www.jboss.com

___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users


Re: [rules-users] single binding for or CE flagged by compiler

2009-03-16 Thread Wolfgang Laun
2009/3/16 Edson Tirelli tire...@post.com


This is an old discussion. Single binding on or is a non-orthogonal
 special case on the language syntax that was introduced in the early days
 when we only had infix CEs. When we started to support prefix CE, the
 special case was not updated, and as a result, the single binding works only
 with infix.


The example I've posted is practically identical to Example 7.55, or with
binding. So, if it's not in the language, it'd better not be in the
documentation :-)

As for the individual binding, as in
  (or $t : Trigger(fa == 1)
$t : Trigger(fa == 2))
the documentation ought to caution against using different names, at least
when these names are used on the RHS.

I agree that or groups with bindings on patterns are tricky. But is the form
that's now accepted by the compiler less error-prone than the one the
compiler refuses?

Wolfgang
___
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users