clipsjess

Why isn't variable x referenced well?


In the following jess / clips code, variable x is not well referenced. Why?

(assert (item 2))
(assert (item 12))

(defrule ex1not
    (not (item ?x))
    (item ?y & (> ?x 10)) <- HERE I GET "No such variable x"
    =>
)

Solution

  • The first pattern matches in the absence of a fact (item ?x), for any value of ?x; it is true when there are no (item) facts at all. The second pattern would then try to compare that ?x to 10. If we were somehow at the second pattern, then since ?x didn't match anything, it has no value, so you can't compare it to anything.

    If you edit your question to add what you're actually trying to express, in English, I can edit my answer to show you how.