In jess the way to return a string from a rule is like that :
(defrule welcome-toddlers
"Give a special greeting to young children"
(person {age < 3})
=>
(printout t "Hello, little one!" crlf))
My question is how implement the return function, this is what I want:
(defrule welcome-toddlers
"Give a special greeting to young children"
(person {age < 3})
=>
(return "Hello, little one!"))
if not possible how do that in drools ??
A rule isn't called like a function - so your question doesn't make sense. Rules fire, due to what happens in Working Memory, in some (apparently) random order - so where should that string from one of those rules go? The (run)
function (fireAllRules
method) just returns the number of rules that were fired, and that's that.
Where would you want to have that string resulting from welcome-toddlers? A way of passing data that's being created in a rule to that point in your application has to be selected. Here's some popular options:
greeting
to person and store it there. (Take care not to cause an endless loop.)Apart from some differences in terminology, it's just the same thing in Drools.
Both systems have documentation where you can find all the details to this and other issues.