我正在尝试学习克拉规则-“ http://www.clara-rules.org/docs/firststeps/”中出现的clojure
(ns with-mongo.clara.example
(:require [clara.rules :refer :all]))
(defrecord SupportRequest [client level])
(defrecord ClientRepresentative [name client])
(defrule is-important
"Find important support requests."
[SupportRequest (= :high level)]
=>
(println "High support requested!"))
(defrule notify-client-rep
"Find the client representative and request support."
[SupportRequest (= ?client client)]
[ClientRepresentative (= ?client client) (= ?name name)]
=>
(println "Notify" ?name "that"
?client "has a new support request!"))
在REPL中执行以下操作
(-> (mk-session 'with-mongo.clara.example)
(insert (->ClientRepresentative "Alice" "Acme")
(->SupportRequest "Acme" :high))
(fire-rules))
但是我在日食中得到的是 CompilerException java.lang.RuntimeException:无法解析符号:在此上下文中的防火规则,编译:(C:\ Users \ x \ AppData \ Local \ Temp \ form-init8304513432405616575.clj:1:2)
有人有任何细节吗?
答案 0 :(得分:0)
您之前尚未在REPL中require
d clara.rules
。例如。运行
(require '[clara.rules :refer :all]))
第一。 (或首先在此处运行自己的ns
-取决于您要如何运行/使用REPL以及如何使用Eclipse(此处为非Eclipse用户))
那么为什么它抱怨fire-rules
而不是mk-session
?那是由于线程宏->
的工作方式。如果您的代码macroexpand
抛出,您将看到fire-rules
实际上是第一个调用的函数。
答案 1 :(得分:0)
我面临的问题是由于版本不匹配
:dependencies [[org.clojure/clojure "1.6.0"]
[com.novemberain/monger "3.0.0-rc2"]
[ring "1.4.0"]
[ring/ring-json "0.4.0"]
[compojure "1.4.0"]
[com.cerner/clara-rules "0.19.0"]])
我正在使用1.6.0制作Clojure,并更新为Clojure“ 1.7.0”之后。克拉拉规则被触发。
:dependencies [[org.clojure/clojure "1.7.0"]
[com.novemberain/monger "3.0.0-rc2"]
[ring "1.4.0"]
[ring/ring-json "0.4.0"]
[compojure "1.4.0"]
[com.cerner/clara-rules "0.19.0"]])