Fork me on GitHub
#clara
<
2022-09-02
>
jherrlin13:09:11

Hey! Anyone knows why I get this error?

1. Unhandled java.lang.IllegalArgumentException
   The query {:lhs [{:type repl.Cold, :constraints [], :fact-binding :?cold}],
   :params #{}, :name "repl/cold?"} is invalid or not included in the rule base.
My code looks like this:
(ns repl
  (:require
   [clara.rules :refer [defquery defrule fire-rules insert insert! query mk-session]]))

(defrecord Temperature [temperature])
(defrecord Cold        [temperature])

(defquery cold? [] [?cold <- Cold])

(let [session-with-rules
      (mk-session
       [(quote
         {:ns-name repl,
          :lhs     [{:type        repl.Temperature,
                     :constraints [(= ?temperature temperature) (< temperature -20)]}],
          :rhs     (do (insert! (->Cold ?temperature))),
          :name    "repl/cold-rule"})])
      session-with-rules-and-facts
      (insert
       session-with-rules
       (Temperature. -21))
      evaluated-session
      (fire-rules session-with-rules-and-facts)]
  (query evaluated-session cold?))

ethanc13:09:10

Hey @UAEV0STAA, I believe that the error you mentioned is occurring, because during construction of the session only the “temperature” production is being provided. I believe that the mk-session call should look something like:

(mk-session
       [(quote
         {:ns-name repl,
          :lhs     [{:type        repl.Temperature,
                     :constraints [(= ?temperature temperature) (< temperature -20)]}],
          :rhs     (do (insert! (->Cold ?temperature))),
          :name    "repl/cold-rule"})
        cold?])

jherrlin13:09:29

Nice! Awesome! Thank you so much! It worked out!

👍 2
ethanc13:09:00

Glad to help