Skip to content

Instantly share code, notes, and snippets.

Created April 15, 2016 02:46
What would you like to do?
Example demonstrating use of clojure.lang.Keyword as the fact type in Clara rule constraints
clara.test-rules> (defrule arule [clojure.lang.Keyword (= :a)] => (println "I fired"))
clara.test-rules> (-> (mk-session [arule]) (insert :a) (fire-rules))
I fired
#object[clara.rules.engine.LocalSession 0x2c848a4e "clara.rules.engine.LocalSession@2c848a4e"]
clara.test-rules> (-> (mk-session [arule]) (insert :b) (fire-rules))
I fired
#object[clara.rules.engine.LocalSession 0x107e6fae "clara.rules.engine.LocalSession@107e6fae"]
clara.test-rules> (defrule arule2 [clojure.lang.Keyword (= this :a)] => (println "I fired"))
clara.test-rules> (-> (mk-session [arule2]) (insert :a) (fire-rules))
I fired
#object[clara.rules.engine.LocalSession 0xdd47412 "clara.rules.engine.LocalSession@dd47412"]
clara.test-rules> (-> (mk-session [arule2]) (insert :b) (fire-rules))
#object[clara.rules.engine.LocalSession 0x69d4b2a "clara.rules.engine.LocalSession@69d4b2a"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment