[rules-dev] Backwards chaining: the difference between input and output variables
Geoffrey De Smet
ge0ffrey.spam at gmail.com
Wed Apr 20 05:16:04 EDT 2011
Mark and I were discussing backwards chaining
http://blog.athico.com/2011/04/backward-chaining-emerges-in-drools.html
on IRC and we 'd like your opinion on a design issue.
The example
========
Let's say you have this data:
Location("crackers", "kitchen")
Location("apple", "kitchen")
Location("chocolate", "living room")
Location("chips", "living room")
Let's say you have this code:
|query| |editableThings( String thing, String location ) |
|||Location(thing, location)|
|end|
And then these 3 rules:
|rule| |outputinput
||when|
|||Here( loc : location) |
|||?||editableThings||(food, ||loc||;)|
|then|
System.out.println("Food " + f + " at location " + loc);
// Output:
// Food crackers at location kitchen
// Food apple at location kitchen
|end
|
|rule| |outputOutput
||when|
|||?||editableThings||(food, ||loc||;)|
|then|
System.out.println("Food " + f + " at location " + loc);
// Output:
// Food crackers at location kitchen
// Food apple at location kitchen
// Food chocolate at location living room
// Food chips at location living room
|end
|
|rule| |typo
||when|
|||Here( looc : location) |
|||?||editableThings||(food, ||loc||;)|
|then|
System.out.println("Food " + f + " at location " + loc);
// Output:
// Food crackers at location kitchen
// Food apple at location kitchen
// Food chocolate at location living room
// Food chips at location living room
|end|
The discussion
=========
Both rules have the same statement:
|?||editableThings||(food, ||loc||;)|
||In the outputInput rule, "|||loc|||" is an input variable.
||In the outputOutput rule, "|||loc|||" is an output variable.
I am wondering if we don't need a visual demarcation that a variable is
an output variable,
to make it stand out of an input variable?
Proposition 1: Suffix output variables with ":"
|rule| |outputinput
||when|
|||Here( loc : location) |
|||?||editableThings||(food:, ||loc||;)|
|then ... end
|
|rule| |outputOutput
||when|
|||?||editableThings||(food:, ||loc:||;)|
|then ... end|||
|rule| |typo
||when|
|||Here( looc : location) |
|||?||editableThings||(food:, ||loc||;) // compiler error because input
variable loc is not declared|||
|then ... end|
--
With kind regards,
Geoffrey De Smet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-dev/attachments/20110420/c91586e5/attachment.html
More information about the rules-dev
mailing list