Fork me on GitHub
#clara
<
2018-03-14
>
afurmanov18:03:48

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))

afurmanov18:03:59

creates infinite recursion?

ethanc18:03:40

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

ethanc18:03:01

@alex.furmanov

zylox18:03:41

"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

zylox18:03:06

http://www.clara-rules.org/docs/truthmaint/ truth maintenance is the name of the game