This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-10-26
Channels
- # announcements (28)
- # asami (13)
- # babashka (10)
- # beginners (170)
- # boot (1)
- # calva (35)
- # cider (21)
- # circleci (13)
- # clara (6)
- # clj-http (1)
- # clj-kondo (29)
- # cljdoc (5)
- # clojure (89)
- # clojure-czech (2)
- # clojure-europe (20)
- # clojure-france (16)
- # clojure-nl (6)
- # clojure-uk (5)
- # clojurescript (80)
- # community-development (6)
- # conjure (13)
- # cursive (18)
- # datascript (9)
- # datomic (1)
- # duct (1)
- # gratitude (2)
- # helix (7)
- # jobs (2)
- # kaocha (3)
- # lsp (22)
- # malli (5)
- # meander (1)
- # other-languages (34)
- # pathom (18)
- # polylith (24)
- # quil (10)
- # re-frame (5)
- # releases (1)
- # remote-jobs (4)
- # reveal (7)
- # shadow-cljs (8)
- # tools-deps (53)
Given the definitions below:
(ns ck.repro
(:require [clara.rules :as rules :refer [defsession defrule defquery]]))
(defrecord MakeStuff [stuff])
(defrecord Stuff [foo])
(defrule add-stuff
[:not [:exists [Stuff]]]
=>
(println "Add stuff")
(rules/insert! (->MakeStuff (->Stuff "foo"))))
(defrule make-stuff
[?make-stuff <- MakeStuff (= ?stuff stuff)]
=>
(println "Make stuff")
(rules/insert-unconditional! ?stuff))
(defquery make-stuff?
[]
(?make-stuff <- MakeStuff))
(defrule exists-stuff
[:exists [Stuff]]
=>
(println "Found stuff"))
(def session (-> (rules/mk-session 'ck.repro)
(rules/fire-rules)))
(println "make-stuff?" (rules/query session make-stuff?))
I get the following output:
Add stuff
Make stuff
Found stuff
make-stuff? ({:?make-stuff #ck.repro.MakeStuff{:stuff #ck.repro.Stuff{:foo foo}}})
I would have expected that the make-stuff
rule would cause the MakeStuff
fact inserted by add-stuff
to be retracted by truth maintenance. Am I missing something?The make-stuff
rule is using insert-unconditional!
which will prevent the fact inserted from being retracted. Otherwise you would have an infinite loop with the above stated rules
bizarre…. At first blush i would say that something about the “Exists” accumulator is acting suspiciously in the retraction path. For example, written differently:
(r/defrule add-stuff
[:not [Stuff]]
=>
(println "Add stuff")
(r/insert! (->MakeStuff (->Stuff "foo"))))
Add stuff
Make stuff
Found stuff
make-stuff? ()
additional sanity:
(r/defquery stuff?
[]
(?stuff <- Stuff))
nets the expected:
Add stuff
Make stuff
Found stuff
make-stuff? ()
stuff? ({:?stuff #Stuff{:foo foo}})
@dave.dixon what version of clara are you running?