Weily,
When you use AND between patterns, you are saying the engine: find
one fact that match the first pattern and find another fact that matches
the second pattern. If you want the same fact to match more than one
"constraint", simply write all constraints inside the same pattern. I
guess this is what you are looking for:
when
$student: Student(examDate == null, $startDate : startDate
->(utilService.dateWithin($startDate,(new Date()),7, utilService.UNIT_DAY)))
then
println("...")
end
The above will match each single fact that complies to both constraints.
BTW, if you indeed want to match more than one fact using AND between
patterns, you don't need to explicit writing the AND as it is already
implicit:
when
$s1 : Student(examDate == null)
$s2 : Student($startDate : startDate
->(utilService.dateWithin($startDate,(new Date()),7,
utilService.UNIT_DAY))))
then
println("...")
end
Above example will match all possible combinations of 2 facts, as
long as the first fact matches the first pattern (and it will be bound
to variable $s1) and the second fact matches second pattern (and it will
be bound to variable $s2). The above is exactly the same of:
when
$s1 : Student(examDate == null) AND
$s2 : Student($startDate : startDate
->(utilService.dateWithin($startDate,(new Date()),7,
utilService.UNIT_DAY))))
then
println("...")
end
Regarding syntax, we are working on parser improvements just to avoid
any confusion like the one you reported in the first e-mail, but the
semantics of conditional elements (and, or, not, exists, etc) will not
change and it is important you understand them.
Hope it helps.
[]s
Edson
weily li wrote:
Hi ALL,
Here is several test cases:
facts feeded: 5 Students.
1.
When
Student(examDate == null);
Then
println("..");
<expected>: one line printed out
<result>: one line printed out
2.
When
Student($startDate : startDate
->(utilService.dateWithin($startDate,(new Date()),7,
utilService.UNIT_DAY)))
Then
println("...")
<expected>: three lines printed out
<result>: three lines printed out
3.
when
(Student(examDate == null) and Student($startDate : startDate
->(utilService.dateWithin($startDate,(new Date()),7,
utilService.UNIT_DAY))))
then
println("...")
<expected>: one line printed out
<result>: three lines printed out(same as scenario 2)
4.
when
$s : (Student(examDate == null) and Student($startDate : startDate
->(utilService.dateWithin($startDate,(new Date()),7,
utilService.UNIT_DAY))))
then
println($s.get....)
At scenario 4, it should assign the Student which meet all columns to
$s. right?
Could anyone help explain how to make 'AND' work as expected?
Thanks
Best Regards
Weily
--
---
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
IT executives: Red Hat still #1 for value
http://www.redhat.com/promo/vendor/
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email