On May 13, 2008, at 12:10 AM, Peter Santos wrote:
>
> String rules ="(defrule Verifica_Funcao";
> rules +="(Exerc_Funcao {Treinado == nao})";
> rules +="=>";
> rules +="(bind ?Humano (+ ?Humano 3)))";
>
>
> engine.executeCommand(rules);
> engine.executeCommand("(run)");
> engine.executeCommand("(store Newuser(+ ?Humano))");
>
>
The variable ?Humano is a local variable; it exists only on the right
hand side of rule Verifica_Funcao. To define global variables --
variables that are visible anywhere in a program -- you can use the
"defglobal" construct:
engine.executeCommand("(defglobal ?*Humano* = 0)");
String rules ="(defrule Verifica_Funcao";
rules +="(Exerc_Funcao {Treinado == nao})";
rules +="=>";
rules +="(bind ?*Humano* (+ ?*Humano* 3)))";
engine.executeCommand(rules);
engine.executeCommand("(run)");
engine.executeCommand("(store Newuser(+ ?Humano))");
There are a few other problems with this code. First, the rule will
never match the fact you've created because nao is an RU,SYMBOL, but
you've populated your fact with RU.STRING data. Either use RU.SYMBOL
for the slot data, or use Treinado == "nao", with quotes.
Finally, in the expression (store Newuser (+ ?Humano)), the "+"
function isn't doing anything; it's just inefficient and messy. Just
use (store Newuser ?Humano) or, of course, (store Newuser ?*Humano*) .
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012
ejfried@...
Livermore, CA 94550
http://www.jessrules.com--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users
you@...'
in the BODY of a message to
majordomo@..., NOT to the list
(use your own address!) List problems? Notify
owner-jess-users@....
--------------------------------------------------------------------