[rules-users] matching multiple facts in a rule using a DSL template
Erik Clairiot
erik at clairiot.com
Wed Jul 29 05:42:10 EDT 2009
Okey, I should have spend more time with DSL...
I didn't know it was possible to use a matching pattern either for variable
name :
[when] there is "{name}" as {key}={key} : Variable(id == "{name}")
Sorry for unnecessary posting, have a nice day.
Erik
On Tue, 28 Jul 2009 17:43:04 +0200, Erik Clairiot <erik at clairiot.com>
wrote:
> 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
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
More information about the rules-users
mailing list