Nikita Fedyashev
Nikita Fedyashev

Reputation: 18993

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, e.g.

(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".

(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.

Is there any way to do in without falling back to lower-level fact-type-fn and regular Clojure maps?

Upvotes: 1

Views: 138

Answers (1)

cfrick
cfrick

Reputation: 37008

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)).

Since defrecord:s result in a class in their respective namespace/package they are fine here.

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.

Upvotes: 2

Related Questions