clara

liebs 2023-12-05T18:42:50.045469Z

Hi there, Clara noob question: I have inserted a fact into memory called TimeLimit. I've tried various simple queries that look correct to me (based on what I can see in documentation), but I get an IllegalArgumentException every time, telling me the query is invalid or not included in the rule base. Do facts also need to have their own rules created by defrule?

ethanc 2023-12-05T18:48:58.643939Z

do you have a small sample of how you are making/querying the session?

liebs 2023-12-05T18:55:32.204339Z

In the RHS of my rule I have

(insert! (->TimeLimit "10 business days" "preliminary"))
and to make my query as dumb as possible I did
(defquery nothing
  []
  [?time-limit <- e/TimeLimit])
exception:
; Execution error (IllegalArgumentException) at clara.rules.platform/throw-error (platform.cljc:5).
; The query {:lhs [{:type e/TimeLimit, :constraints [], :fact-binding :?time-limit}], :params #{}, :name "user/nothing"} is invalid or not included in the rule base.

ethanc 2023-12-05T18:58:15.566359Z

is it fair to assume the loading/running of these rules looks something like:

(-> (mk-session [rulename nothing]) 
  (insert (->SomeEntryFact))
  fire-rules
  (query nothing))

liebs 2023-12-05T18:58:57.023109Z

Does it matter that I've bound my session to a var and then queried it using that name? I would assume that's fine.

ethanc 2023-12-05T19:00:09.322149Z

binding it as a variable should be fine

liebs 2023-12-05T19:07:14.378449Z

hm deep_thinking I'm sure I'm doing something silly

liebs 2023-12-05T19:08:21.408459Z

Do my queries need to be defined in the same ns I load for my session? That must be what it is

ethanc 2023-12-05T19:09:58.238319Z

if you aren’t explicitly providing namespaces or rule/query defs to the mk-session call, then they wouldn’t likely be loaded. something like:

(mk-session)
by default scans the current namespace to load rule/query defs

liebs 2023-12-05T19:10:51.102019Z

got it, I knew it was gonna be something dumb like that. Thanks.

liebs 2023-12-05T19:11:07.315539Z

dumb that I was doing I mean

ethanc 2023-12-05T19:11:47.559599Z

its not really dumb. Im not a huge fan of default behavior all that much… feels a bit too “magic” to me

liebs 2023-12-05T19:12:42.789309Z

I definitely made a somewhat arbitrary decision here to have my rules in one ns and queries in another, so lesson learned there but yeah defaults not always my friend either.

ethanc 2023-12-05T19:14:51.563469Z

to your credit, you are not the first and certainly not the last to decide to do it that way. I am aware of other implementations that decided to retroactively add “transitive namespace scanning” to their codebase to determine all of the possibly available rules. I highly recommend that everyone avoid that though 😄

😅 1
ethanc 2023-12-06T04:41:57.025769Z

> I highly recommend that everyone avoid that though transitively loading namespaces that is. Separation of of rules and queries is likely fine, but when loading them ideally be specific. ex.

(def session (mk-session `rules-namespace  `queires-namespace))
or even more specific by providing individual productions. unraveling the intertwined transitive namespaces can make ones head spin