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))
creates infinite recursion?
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
forever
"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
Thanks!