clara

http://www.clara-rules.org/
afurmanov 2018-03-14T18:20:48.000261Z

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

afurmanov 2018-03-14T18:20:59.000261Z

creates infinite recursion?

ethanc 2018-03-14T18:27:40.000284Z

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

👍 3
ethanc 2018-03-14T18:27:55.000715Z

forever

ethanc 2018-03-14T18:28:01.000731Z

@alex.furmanov

zylox 2018-03-14T18:28:41.000764Z

"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

👍 1
zylox 2018-03-14T18:30:06.000651Z

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

👍 3
afurmanov 2018-03-14T18:35:04.000104Z

Thanks!