Skip to content

Instantly share code, notes, and snippets.

@WilliamParker
Created January 12, 2016 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WilliamParker/b109dba95f36187f54d0 to your computer and use it in GitHub Desktop.
Save WilliamParker/b109dba95f36187f54d0 to your computer and use it in GitHub Desktop.
Test namespace for duplicate rules in clara-rules
(ns clara.examples.duplicates
(:require [clara.rules.accumulators :as acc]
[clara.rules :refer :all]
[clara.rules.compiler :as c]))
(defrecord Temperature [t])
(defrecord Cold [t])
(defrule is-cold?
[Temperature (= ?t t)]
=>
(insert! (->Cold ?t)))
(defquery cold-query
""
[]
[?c <- Cold])
(def dup-session (mk-session [is-cold? is-cold? cold-query]))
(defn get-cold []
(-> dup-session
(insert (->Temperature 10))
fire-rules
(query cold-query)))
(let [productions [is-cold? is-cold?]
beta-struct (c/to-beta-tree productions)
beta-tree (c/compile-beta-tree beta-struct)
alpha-tree (c/to-alpha-tree beta-struct)
alpha-nodes (c/compile-alpha-nodes alpha-tree)
rulebase (c/build-network beta-tree alpha-nodes productions)]
(def debug {:beta-struct beta-struct
:beta-tree beta-tree
:alpha-tree alpha-tree
:alpha-nodes alpha-nodes
:rulebase rulebase}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment