简体   繁体   中英

Unable to run clara rules clojure program from eclipse

I am trying to learn clara rules - clojure which is present in " http://www.clara-rules.org/docs/firststeps/ "

(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!"))

Executing the following in REPL

 (-> (mk-session 'with-mongo.clara.example)
     (insert (->ClientRepresentative "Alice" "Acme")
                  (->SupportRequest "Acme" :high))
          (fire-rules))

But what I get in eclipse is CompilerException java.lang.RuntimeException: Unable to resolve symbol: fire-rules in this context, compiling:(C:\\Users\\x\\AppData\\Local\\Temp\\form-init8304513432405616575.clj:1:2)

Does anyone has any details on it?

You have not require d clara.rules in your REPL beforehand. Eg run

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

first. (or run your own ns there first - that depends on how you want to run/use the REPL and what eclipse allows you to use (non-eclipse-user here))

So why does it complain about fire-rules and not mk-session ? That is due to the way the threading macro -> works. If you macroexpand your code, that throws, you will see, that fire-rules is actually the first function called.

The issue I was facing was due to the version mismatches

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

I was using 1.6.0 for clojure and after updating to clojure "1.7.0". Clara rules are getting triggered.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM