> It's very unlikely that it's this rule that's causing the problem. I
> wonder if this is yet another case of the unbound-variable problem
> that's been reported lately. If you have a rule that uses the value
> of
> a variable before it's defined, Jess will *usually* notice. But
> sometimes it doesn't, and as a result you get an error message
> similar
> to this at runtime. Look at all of your rules to make sure that all
> your LHS variables are bound to a value before being used in a
> function call.
>
>
This could be the case, but if it is, I don't understand it.
I replicated my error to a simple version that can immediately be saved
to a Jess batch file for execution:
(clear)
(watch all)
(import foo.*)
(deftemplate answer
(slot id)
(slot text))
(defclass loan Loan)
(definstance loan (new Loan foo alles) static)
;;(deftemplate loan (slot id) (slot reason))
;;(deffacts leningen (loan (id "foo") (reason "any")))
(defglobal ?*crlf* = "")
(deftemplate foo
(slot id))
(deffacts testdata
(foo (id "foo")))
(do-backward-chaining answer)
(defrule get-answer
(declare (auto-focus TRUE))
(need-answer (id "reason"))
=>
(assert (answer (id "reason") (text "car"))))
(defrule test-rule-logical
(declare (auto-focus TRUE))
;; (logical (guard))
(logical (foo (id ?id)))
(logical (initial-fact) (answer (id "reason") (text ?reason)))
(logical (loan (id ?id) (reason "any"|?reason) ))
=>
(assert (ok)))
(defrule test-rule-no-logical
(declare (auto-focus TRUE))
(guard)
(foo (id ?id))
(answer (id "reason") (text ?reason))
(loan (id ?id) (reason "alles"|?reason))
=>
(assert (ok)))
(reset)
(run)
The code for the Loan Java object is also simplified:
package foo;
public class Loan {
String id;
String reason;
public Loan(String i, String r){
id = i;
reason = r;
}
public void setId(String i){ id = i; }
public String getId(){ return id;}
public void setReason(String r){ reason = r; }
public String getReason(){ return reason;}
}
I noted several things:
1. The test-rule-no-logical works in any case. The (ok) fact gets
asserted, both for the loan regular fact and the loan shadowfact.
2. The test-rule-logical never works correctly. The (ok) fact never
gets asserted. However, for the loan deftemplate, the loan pattern in
the rule just never matches. For the loan shadowfact, the loan pattern
gives the bad index error after the answer fact is asserted(so probably
when the loan pattern gets patternmatched).
About the unbound variables. I guess the (reason "any"|?reason)
constraint is responsible for the error, but ?reason gets bound
correctly without the logicals. In any case, as far as I see, the foo
pattern binds ?id, the answer pattern binds ?reason and the loan
pattern matches or "any" or the bound ?reason variable for its reason
slot.
Maybe the logical CE messes up locally bound variables for the LHS of
rules? Or maybe I use the logicals in an incorrect way?
Other rules with logical give me similar errors, like a variable that
is first bound with a regular pattern, then used in a not pattern, and
then it gives an unbound variables error, while the variable was
actually correctly bound before.
Regards,
Steffen.
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------