I am trying to use a defquery on LHS to match if the sum is greater than a
threshold.  But when I run the attached file, the rule doesn't fire.

Thanks,
Khaled

test.clp
---------
(clear)

(defquery q
        (a ?i ?j ?v)
)

(deffunction sum (?__it ?__n)
        (bind ?s 0)
        (while (?__it hasNext)
                (bind ?token (call ?__it next))
                (bind ?fact (call ?token fact 2))
                (bind ?slot (fact-slot-value ?fact __data))
                (bind ?datum (nth$ ?__n ?slot))
                (bind ?s (+ ?s ?datum))
        )
        return ?s
)

(defrule r1
        (test (> (sum (run-query q) 3) 10))
        =>
        (printout t "r1" crlf)
)

(deffacts ff 
        (a 0 0 1)
        (a 0 1 2)
        (a 0 2 3)
        (a 1 0 4)
        (a 1 1 5)
        (a 1 2 6)
        (a 2 0 7)
        (a 2 1 8)
        (a 2 2 9)
)

(reset)
(printout t "sum = " (sum (run-query q) 3) crlf)
(run)


Jess> (batch test.clp)
sum = 45
0
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]
---------------------------------------------------------------------

Reply via email to