This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-11-16
Channels
- # beginners (103)
- # boot (48)
- # cider (2)
- # clara (12)
- # cljsrn (9)
- # clojure (133)
- # clojure-art (3)
- # clojure-dev (9)
- # clojure-korea (7)
- # clojure-russia (228)
- # clojure-spec (8)
- # clojure-uk (26)
- # clojurescript (131)
- # cursive (8)
- # datomic (30)
- # emacs (4)
- # events (2)
- # hoplon (47)
- # lein-figwheel (5)
- # off-topic (1)
- # om (12)
- # onyx (337)
- # perun (23)
- # planck (15)
- # proton (3)
- # re-frame (5)
- # spacemacs (20)
- # untangled (97)
- # utah-clojurians (1)
- # yada (13)
I think I’m missing something with accumulators - I’d like to have some sort of collection of reasons that something failed
Originally I thought the best way to do that would be to have rules for each mode of failure
And those rules would add a fact with a reason
Test code here:
(defrecord DomainObject [name1 name2])
(defrecord Invalid [reason])
(defrule name1-not-test
[DomainObject (not= name1 "test")]
=>
(insert! (->Invalid "test")))
(defrule name2-is-test
[DomainObject (= name2 "test")]
=>
(insert! (->Invalid "name2 test")))
(defrule collect-invalids
[?reasons <- (acc/all) :from [Invalid]]
=>
(prn "Invalid for: " (map :reason ?reasons)))
When run with:
(-> (mk-session 'clara-playground.core)
(insert (->DomainObject "nottest" "test"))
(fire-rules))
The output is
"Invalid for: " ()
"Invalid for: " ("test" "name2 test")
After reading more on the accumulator side, I added a restriction
And rewrote collect-invalids
as
(defrule collect-invalids
[?reasons <- (acc/all) :from [Invalid (= ?reason reason)]]
=>
(prn "Invalid for: " (map :reason ?reasons)))
But that output is
"Invalid for: " ("test")
"Invalid for: " ("name2 test")
Any suggestions on what I’m missing?
If it’s unclear, I want collect-invalids
to fire a single time, with all the reasons
Or is this something that’s better left to queries?