I have a similar situation but I wanted to be able to distinguish NIL
cases.  I used the defadvice to wrap the various numeric comparison
operators to handle this in the way I wanted.  In my case, I treat NIL
as "unknown" and all of the tests fail (e.g. NIL is neither greater,
less, or equal to any number).

E.g.
;If any argument to > is NIL, then the test fails
(defadvice before > (foreach ?arg $?argv (if (eq ?arg nil) then (return
FALSE))))

-Russ

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Henrique Lopes Cardoso
Sent: Thursday, July 03, 2008 1:29 PM
To: [email protected]
Subject: JESS: Rule comparing slot values that can be omitted

Hi,

I have tried the straightforward example below. I define two simple
deftemplates and a rule that compares their slots, which are assumed to
be numeric. Then, I incidentally assert a fact on which I do not define
a value for a slot.
When the rule is evaluated (after the second assertion), I immediately
get an error.

Now, I understand the error. But maybe Jess should be nicer by noticing
that if the comparison cannot be made, then it should simply not fire
the rule (quietly).

Henrique

---
Jess, the Rule Engine for the Java Platform Copyright (C) 2008 Sandia
Corporation Jess Version 7.1RC1 6/23/2008

Jess> (deftemplate a (slot s))
TRUE
Jess> (deftemplate b (slot s))
TRUE
Jess> (defrule r1 (a (s ?sa)) (b {s < ?sa}) => (printout t "Yes!" crlf))
TRUE
Jess> (assert (a))
<Fact-0>
Jess> (assert (b (s 1)))
Jess reported an error in routine <
        while executing (< ?__synth0(1,0,-1) ?sa(0,0,-1))
        while executing rule LHS (Node2)
        while executing rule LHS (TECT)
        while executing (assert (MAIN::b (s 1))).
  Message: Not a number: nil.
  Program text: ( assert ( b ( s 1 ) ) )  at line 5.
Jess>


--------------------------------------------------------------------
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]
--------------------------------------------------------------------



--------------------------------------------------------------------
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]
--------------------------------------------------------------------

Reply via email to