[rules-users] matching multiple facts in a rule using a DSL template

Erik Clairiot erik at clairiot.com
Tue Jul 28 11:43:04 EDT 2009


Hello,

I recently started to use DSL template within my rules.
In the LHS, I oftenly match conditions against multiple facts, facts that I
want to modify in the RHS.

example :

when
  $v1 : Variable(id == "A")
  $v2 : Variable(id == "B")
then
  $v1.setFoo();
end

If I write a dsl template like that :

[when] there is "{id}"=v:Variable(id == "{id}")
[then] foo me=v.setFoo();

and a dsl rule like that

when
  there is "A"
  there is "B"
then
  foo me
end

the execution will produce the error "Duplicate declaration for variable
..."

I understand why it occurs.

how to specify a constraint upon the fact matched ? Dunno if it is
possible, my opinion will be to create another dsl rule, that is supposed
to match with the "foo me", but it does not seem to be very convenient.

Is there a way to use an array for variable assignement in the RHS ? like

[when] there is "{id}"=v[]:Variable(id == "{id}")
[then] foo me=v[].setFoo();

and use it in the RHS of the rule like

when
  there is "A"
  there is "B"
then
 foo me [0] // will cause foo me on the first matched fact
end

There are a lot of chances this does not exist, and works like that, maybe
I am not using DSL well and it is bad idea to match multiple fact with the
same dsl template.

Can someone help me on that ? It is just a question, I am not stuck on
this, but interested on how to deal with that.

Thanks.

Erik




More information about the rules-users mailing list