简体   繁体   English

Clara 规则:是否可以将 defrecord-s 提取到单独的 Clojure 命名空间中?

[英]Clara rules: Is it possible to extract defrecord-s into a separate Clojure namespace?

New facts inserting works fine but I can not find a way to fix defrule-s, eg新的事实插入工作正常,但我找不到修复 defrule-s 的方法,例如

(defrule is-important
  "Find important support requests."
  [SupportRequest (= :high level)]
  =>
  (println "High support requested!"))

[domain/SupportRequest (=:high level)] doesn't work due to "Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:436). SupportRequest". [domain/SupportRequest (=:high level)]由于"Execution error (ClassNotFoundException) at java.net.URLClassLoader/findClass (URLClassLoader.java:436). SupportRequest".

(ns clara.compatibility
  (:require [clara.rules.accumulators :as acc]
            [clara.tools.tracing :as tracing]
            [clara.tools.inspect]
            [clara.domain :as domain]
            [clara.rules :refer :all]))

The reason why I wanted to extract those defrecords is that the domain is rather big and I wanted to minimize the number of code lines in one file.我想提取这些defrecords的原因是域相当大,我想尽量减少一个文件中的代码行数。

Is there any way to do in without falling back to lower-level fact-type-fn and regular Clojure maps?有什么办法可以在不退回到较低级别的事实类型 fn 和常规 Clojure 映射的情况下做吗?

Clara expects a class here (I am unaware for the exact reasons; I'd assume for better Java-interop (as in, using it from Java)). Clara 在这里期望 class (我不知道确切的原因;我假设更好的 Java 互操作(如从 Java 中使用它))。

Since defrecord :s result in a class in their respective namespace/package they are fine here.由于defrecord :s 在它们各自的命名空间/包中导致 class ,因此它们在这里很好。

Yet if you put them somewhere outside the rules file, you would have to deal with them as if they were classes: you have to :import them instead of :require :ing them.然而,如果你把它们放在规则文件之外的某个地方,你将不得不把它们当作类来处理:你必须:import它们而不是:require :ing 它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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