heh, I made a mistake with the rule
( Location(z, y;) and ?hasFood(x, z;) )
should be
( Location(z, y;) and hasFood(x, z;) )
Otherwise it's not reactive, and then ordering matters.
With that change I can do the insertions in any order and all
is fine.
This works for the example you gave. But the one taken from
the "Introduction" still depends on the order the facts are
inserted. Below is the .drl, which does not need any pojos.
Rule kickOff contains the order that produces nothing to see
and eat:
You are in the table
You can see []
You can eat []
Insert Here after the others, and it works.
-W
import java.util.List
declare Thing
thing : String @key
end
declare Edible extends Thing
end
declare Location extends Thing
location : String @key
end
declare Here
place : String
end
rule kickOff
when
then
System.out.println( "insert Here" );
insert( new Here( "table" ) );
System.out.println( "insert Edible" );
insert( new Edible( "peach" ) );
System.out.println( "insert Location" );
insert( new Location( "peach", "table" ) );
end
# 2011-06-22
query isContainedIn( String x, String y )
Location(x, y;)
or
( Location(z, y;) and /*?*/isContainedIn(x, z;) )
end
query whereFood( String x, String y )
( Location(x, y;) and
Edible(x;) )
or
( Location(z, y;) and /*?*/whereFood(x, z;) )
end
query look(String place, List things, List food)
Here(place;)
things := List() from accumulate( Location(thing, place;),
collectList( thing ) )
food := List() from accumulate( /*?*/whereFood(thing,
place;),
collectList( thing ) )
end
rule reactiveLook
when
Here( $place : place)
/*?*/look($place, $things; $food := food)
then
System.out.println( "You are in the " + $place);
System.out.println( " You can see " + $things );
System.out.println( " You can eat " + $food );
end