_ is bind an unbound field. Just replace with a variable you don't use. _1, _2, _3
would work.
Mark
On 9 Jul 2013, at 10:46, Wolfgang Laun <wolfgang.laun(a)gmail.com> wrote:
On 08/07/2013, Mark Proctor <mproctor(a)codehaus.org> wrote:
> As per the email, we don't' have the nice syntax for list unification - but
> it's just sugar. The same thing can be done, just more verbosely. I've not
> checked this compiles, but it shows the intent.
Next time do so, it's quite interesting, see below…
It was just a sketch that I
took 20s to illustrate for you, written in the email, I expected it not to compile.
> query nextTo(String x, String y, List list)
> isRight( x, y, list )
> or
> isRight( y, x, list )
> end
>
> query isRight(String l, String r, List list)
> l := String() from list[0]
> r := String() from list[1]
> tail : List() from list.subList(1, list.size() )
> isRight( l, r, tail )
> end
>
Copied your rules into a drl, and 5.5.0 crashes with:
Exception in thread "main" java.lang.NullPointerException
at org.drools.rule.builder.QueryElementBuilder.build(QueryElementBuilder.java:59)
at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:180)
at org.drools.rule.builder.PatternBuilder.build(PatternBuilder.java:123)
at org.drools.rule.builder.GroupElementBuilder.build(GroupElementBuilder.java:67)
at org.drools.rule.builder.RuleBuilder.build(RuleBuilder.java:84)
at org.drools.compiler.PackageBuilder.addRule(PackageBuilder.java:2830)
at org.drools.compiler.PackageBuilder.compileRules(PackageBuilder.java:970)
at org.drools.compiler.PackageBuilder.compileAllRules(PackageBuilder.java:879)
at org.drools.compiler.PackageBuilder.addPackage(PackageBuilder.java:871)
at org.drools.compiler.PackageBuilder.addPackageFromDrl(PackageBuilder.java:466)
at org.drools.compiler.PackageBuilder.addKnowledgeResource(PackageBuilder.java:694)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:51)
at org.drools.builder.impl.KnowledgeBuilderImpl.add(KnowledgeBuilderImpl.java:40)
OK, I must not omit an import, but an NPE is uncalled for. So, I added
import java.util.List
and then I get:
### compilation errors ###
Unable to resolve ObjectType 'isRight' : [Rule name='nextTo']
Query's must use positional or bindings, not field constraints:
This error message ought to be rewritten as
"Queries require positional arguments or bindings, not field constraints"
Next, I added some semicolons:
query nextTo(String x, String y, List list)
isRight( x, y, list; )
or
isRight( y, x, list; )
end
query isRight(String l, String r, List list)
l := String() from list.get(0)
r := String() from list.get(1)
tail : List() from list.subList(1, list.size() )
isRight( l, r, tail; )
end
and then I get:
### compilation errors ###
Unable to resolve ObjectType 'isRight' : [Rule name='nextTo']
I had to swap the queries so that the definition of isRight precedes
its use in nextTo. That's a potentially blocking bug, since queries
can be used mutually recursively.
Quite a haul...
Wolfgang