Fork me on GitHub
#clara
<
2021-03-01
>
Mario C.21:03:38

Hey guys, I'm getting started with Clara and creating a few examples but something is not clicking. I created some types and created two queries, like this.

(defrecord Account [total-balance owner])
(defrecord Wallet [type balance])
(defrecord Transaction [type cost])

(defquery get-accounts
  "Query to find the owner's account."
  [:?owner]
  [?account <- Account (= ?owner owner)])

(defquery get-all-accounts
  "Query to return all accounts."
  []
  [?account <- Account])
I inserted some facts like so.
(def temp-sesh (-> (clara/mk-session 'mac)
                     (clara/insert (->Account 10000 "person")
                                   (->Account 1000 "human"))))
But when I try to run the queries I don't get anything back. Just an empty list. (clara/query temp-sesh get-all-accounts) => () and (clara/query temp-sesh get-accounts :?owner "human") => () What am I doing wrong? Also, when I do (inspect temp-sesh) the :insertions key is an empty map. It's almost as if the facts that I am inserting are immediately discarded. Do I need to have rules in order to insert facts?

enn21:03:01

Does it make any difference if you call fire-rules?

ethanc21:03:20

Without firing rules, nothing will be processed

đź‘Ť 3
Mario C.21:03:31

It does, that worked. But why? There aren't any rules...

ethanc21:03:35

i believe that is related to performance, clara doesn’t operate until a user is ready to operate. In certain scenarios, the operation of inserting a fact could trigger a multitude of processing in the sense of truth maintenance. This could be compounded, if the user later adds more facts thus triggering more work. So at some point, it was decided that nothing would occur until fire-rules was called.

ethanc21:03:19

All of the operations would be “pending” until the point that a user determine that they were ready to run.

Mario C.21:03:29

Okay, got it! Thanks, I was confused and couldn't find any docs mentioning that part