This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-27
Channels
- # adventofcode (3)
- # aws (1)
- # beginners (79)
- # boot-dev (1)
- # clara (50)
- # cljs-dev (7)
- # clojure (60)
- # clojure-austin (1)
- # clojure-germany (1)
- # clojure-greece (1)
- # clojure-russia (3)
- # clojure-spec (43)
- # clojure-uk (1)
- # clojurescript (76)
- # data-science (1)
- # datomic (26)
- # docs (2)
- # emacs (7)
- # fulcro (10)
- # hoplon (1)
- # instaparse (1)
- # lumo (3)
- # off-topic (16)
- # om (3)
- # onyx (2)
- # re-frame (3)
- # reagent (24)
- # ring-swagger (10)
- # shadow-cljs (15)
- # spacemacs (1)
- # sql (16)
- # uncomplicate (12)
- # unrepl (47)
When i inspect a session, the value of :fact->explanations key is always nil, despite facts being inserted into the session. My goal is to check what all facts are in the session. Help? CC: @mikerod
However, if you are just doing this for some sort of debugging, you could also add a query that matched any fact and use that to see what is in the session. This query could be a performance issue in a production usage though,.
in the process of debugging, I tried inspect and fact-graph...thats when I came across nil values
But, queries clearly shows that facts are there. So, now just wondering if :fact-explanation or fact-graph should be looked at or not?
@amarjeet your code snipet looks wrong. Perhaps just a typo? You have (insert-all facts base-session)
when it should be (insert-all base-session facts)
- base-session
is first arg
Also, I only see 2 def
in your example. One for base-session
and one for mysession
. I don’t see what you called to try inspecting and looking at the inspection results. That’d be useful too. Pending the above comment I had was just a typo
@amarjeet I think in general you shouldn’t assume much about the state of working memory prior to fire-rules
Take that as a general principle. Things are done sometimes “lazily” in some respects
That doesn’t answer the 2nd part of your question as to what is missing post-rule firing though
I re-checked, post fire-rules, I can see only matched facts, not all inserted ones (in that session)
@amarjeet it seems the purpose of the key :fact->explanations
is to explain derived facts within working memory
Take for example:
:fact->explanations
{#clara.test_rules.B{}
[{:rule {:ns-name clara.test-rules, :lhs [{:type clara.test_rules.A, :constraints []}], :rhs (do (insert! (->B))), :name "clara.test-rules/test-a"},
:explanation #clara.tools.inspect.Explanation{:matches ({:fact #clara.test_rules.A{}, :condition {:type clara.test_rules.A, :constraints []}}), :bindings {}}}]}
the value under it is a list of rules deriving it. There’d be more than one if multiple of these facts were =
in working memory.
(into []
(comp cat
(map :explanation)
(mapcat :matches)
(map :fact))
(vals (:fact->explanations inspect-results)))
combined with (keys (:fact->explanations inspect-results))
sort of gets you thereAlso, an important consideration is that Clara doesn’t hold references to any inserted facts that cannot contribute to any rule
(defrecord A [])
(defrule not-using-a
[:not-a]
=>
(insert! {:not-a true}))
(-> (mk-session [not-using-a])
(insert (->A))
fire-rules)
@alex-dixon has done some more interesting things with session inspection I believe. He may have thoughts on this though.
On the topic of analyzing all facts inserted or that sort of thing. Then again, for dev only, if you are using the typical type hierarchy you could just do
(defquery find-any-fact []
[?f <- Object])
https://github.com/CoNarrative/precept/blob/master/src/cljc/precept/listeners.cljc
Example of abusing clara.listeners 😊
It’s a tremendously well designed interface. This is just one implementation. We set up a core async pipeline to process insertions from outside the session (see in precept.core if interested). Each time there’s an insert we add and remove a listener and divide the listener ops into additions and removals
From there we apply the ops to an atom that represents “current state”
Part of motivation over a query is that queries become part of the rete network so having one that matches on everything wasn’t performant
@amarjeet Just making sure you saw this in case it might be helpful