 (ns aurora.language
   (:require [aurora.btree :as btree])
-  (:require-macros [aurora.macros :refer [apush set!!]]))
+  (:require-macros [aurora.macros :refer [apush aclear set!!]]))
 
 ;; KNOWLEDGE
 


(def kn (knowledge))

(.get-or-create-index kn "know" "edge" #js ["x" "y"])

(.get-or-create-index kn "know" "connected" #js ["x" "y"])

(.add-facts kn "know" "edge" #js ["x" "y"] #js [#js ["a" "b"] #js ["b" "c"] #js ["c" "d"] #js ["d" "b"]])

(.get-or-create-index kn "know" "clauses" #js ["rule-id" "when|know|remember|forget" "clause-id" "name"])

(.get-or-create-index kn "know" "clause-fields" #js ["clause-id" "constant|variable" "key" "val"])

(.add-facts kn "know" "clauses" #js ["rule-id" "when|know|remember|forget" "clause-id" "name"] #js [#js ["single-edge" "when" "get-edges" "edge"]
                                                                                                    #js ["single-edge" "know" "output-connected" "connected"]])

                                                                                             #js ["some-interval" "variable" "in" "zz"]
                                                                                             #js ["rem-bar" "variable" "z" "zz"]])

(.add-facts kn "know" "clauses" #js ["rule-id" "when|know|remember|forget" "clause-id" "name"] #js [#js ["count-overlap" "when" "count-get-foos" "foo"]
                                                                                                    #js ["count-overlap" "when" "count-some-interval" "interval"]
                                                                                                    #js ["count-overlap" "remember" "count-rem-frip" "frip"]])

(.add-facts kn "know" "clause-fields" #js ["clause-id" "constant|variable" "key" "val"] #js [#js ["count-get-foos" "variable" "x" "xx"]
                                                                                             #js ["count-get-foos" "variable" "y" "yy"]
                                                                                             #js ["count-some-interval" "variable" "lo" "xx"]
                                                                                             #js ["count-some-interval" "variable" "hi" "yy"]
                                                                                             #js ["count-some-interval" "variable" "in" "zz"]
                                                                                             #js ["count-rem-frip" "variable" "x" "xx"]
                                                                                             #js ["count-rem-frip" "variable" "w" "ww"]])


(.add-facts kn "know" "has-agg" #js ["rule-id"] #js [#js ["count-overlap"]])

(.add-facts kn "know" "group-by" #js ["rule-id" "var"] #js [#js ["count-overlap" "xx"]])

(.add-facts kn "know" "agg-over" #js ["rule-id" "in-var" "agg-fun" "out-var"] #js [#js ["count-overlap" "zz" "count" "ww"]])

(def flows (compile kn))

(enable-console-print!)
(prn :running)
(.quiesce flows kn (fn [kn] (prn :ticked kn)))

