This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-05
Channels
- # adventofcode (89)
- # announcements (9)
- # babashka (11)
- # beginners (8)
- # biff (5)
- # calva (4)
- # cherry (121)
- # clara (15)
- # clerk (16)
- # clj-kondo (20)
- # clj-otel (2)
- # cljdoc (20)
- # clojure (84)
- # clojure-austin (1)
- # clojure-bay-area (3)
- # clojure-berlin (1)
- # clojure-czech (2)
- # clojure-europe (59)
- # clojure-nl (1)
- # clojure-norway (12)
- # clojure-poland (1)
- # clojure-uk (15)
- # cursive (16)
- # datomic (46)
- # events (3)
- # fulcro (85)
- # graalvm (20)
- # hyperfiddle (11)
- # improve-getting-started (1)
- # lsp (7)
- # off-topic (48)
- # overtone (8)
- # podcasts-discuss (4)
- # re-frame (31)
- # releases (1)
- # ring (12)
- # sci (13)
- # shadow-cljs (8)
- # specter (3)
- # squint (26)
- # xtdb (5)
- # yamlscript (6)
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
?
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.
is it fair to assume the loading/running of these rules looks something like:
(-> (mk-session [rulename nothing])
(insert (->SomeEntryFact))
fire-rules
(query nothing))
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.
hm I'm sure I'm doing something silly
Do my queries need to be defined in the same ns
I load for my session? That must be what it is
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 defsgot it, I knew it was gonna be something dumb like that. Thanks.
dumb that I was doing I mean
its not really dumb. Im not a huge fan of default behavior all that much… feels a bit too “magic” to me
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.
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 😄
> 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