【问题标题】:Unable to run clara rules clojure program from eclipse无法从 Eclipse 运行 clara rules clojure 程序
【发布时间】:2018-12-15 12:46:54
【问题描述】:

我正在尝试学习 clara 规则 - "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))

但是我在 eclipse 中得到的是 CompilerException java.lang.RuntimeException: Unable to resolve symbol: fire-rules in this context, 编译:(C:\Users\x\AppData\Local\Temp\form-init8304513432405616575.clj:1:2)

有没有人有详细的介绍?

【问题讨论】:

    标签: clojure


    【解决方案1】:

    您的 REPL 中没有 required clara.rules。例如。运行

    (require '[clara.rules :refer :all]))
    

    首先。 (或者先在那里运行你自己的ns - 这取决于你想如何运行/使用REPL以及eclipse允许你使用什么(这里是非eclipse用户))

    那么为什么它抱怨fire-rules 而不是mk-session?这是由于线程宏-> 的工作方式。如果你 macroexpand 你的代码,你会看到 fire-rules 实际上是第一个调用的函数。

    【讨论】:

    • (ns with-mongo.clara.example (:require [clara.rules :refer :all])) -- 前两行有我相信的吗?
    • 那么当我们在 REPL 中加载文件时,应该包含这些文件吧?
    • 当我特别添加时(需要'[clara.rules :refer :all]) FileNotFoundException 无法在类路径中找到 clara/rules__init.class 或 clara/rules.clj:clojure.lang.RT。加载(RT.java:443)
    • :依赖关系 [[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"]])
    【解决方案2】:

    我遇到的问题是版本不匹配

      :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"]])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-04-05
      • 1970-01-01
      • 2013-03-06
      • 2014-10-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多