This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-03-14
Channels
- # aleph (2)
- # atlanta-clojurians (5)
- # beginners (38)
- # boot (2)
- # bristol-clojurians (1)
- # cider (31)
- # clara (8)
- # cljs-dev (136)
- # cljsrn (4)
- # clojure (86)
- # clojure-china (1)
- # clojure-greece (1)
- # clojure-italy (24)
- # clojure-nl (1)
- # clojure-spec (21)
- # clojure-uk (19)
- # clojurescript (68)
- # community-development (28)
- # core-async (35)
- # core-logic (4)
- # cursive (1)
- # data-science (1)
- # datascript (1)
- # datomic (46)
- # events (1)
- # figwheel (6)
- # fulcro (11)
- # graphql (3)
- # hoplon (1)
- # jobs (6)
- # jobs-discuss (94)
- # keechma (3)
- # luminus (4)
- # lumo (7)
- # mount (6)
- # off-topic (24)
- # onyx (6)
- # parinfer (31)
- # portkey (3)
- # programming-beginners (16)
- # re-frame (20)
- # reagent (69)
- # remote-jobs (4)
- # ring-swagger (25)
- # schema (1)
- # shadow-cljs (151)
- # spacemacs (2)
- # sql (14)
- # tools-deps (16)
- # uncomplicate (5)
- # unrepl (35)
- # vim (1)
- # yada (72)
Why this code
(ns experiments.a
(:require [clara.rules :as rules]
[clojure.pprint :refer [pprint]]))
(defrecord A [id])
(rules/defrule create-a-if-not-exists
""
[:not [A]]
=>
(println "creating A")
(rules/insert! (->A "a")))
(-> (rules/mk-session)
(rules/fire-rules))
The initial state of the session makes the LHS of your rule evaluate as true
thus it inserts an A
,
which then makes your rule's LHS evaluate as false
causing the truth maintenance of clara to logically retract the A
that was insert.
repeat
"ok i'll insert a if there is no A. Inserting. Ok now lets look at the state of things. Oh there is an A. Retract That thing i inserted. Ok now lets look at the state of things. Oh there is no A. Time to insert A...." ~ Internal monologue of the session repeat ad infinitum
http://www.clara-rules.org/docs/truthmaint/ truth maintenance is the name of the game