Fork me on GitHub
#clara
<
2017-08-18
>
iku00088804:08:03

Has anyone tried using clara-rules via a self hosted cljs compiler?

iku00088804:08:19

I run into errors like this

iku00088804:08:23

cljs.user=> (require 'clara.rules)
            ⬆
WARNING: macroexpand already refers to: cljs.core/macroexpand being replaced by: clojure.reflect/macroexpand at line 33 clojure/reflect.cljs
                     ⬆
WARNING: Use of undeclared Var schema.utils$macros/class at line 25 schema/utils.clj
                     ⬆
WARNING: Use of undeclared Var schema.utils$macros/class at line 32 schema/utils.clj
                           ⬆
WARNING: Use of undeclared Var schema.utils$macros/format at line 36 schema/utils.clj
              ⬆
WARNING: No such namespace: clojure.lang.Compiler, could not locate clojure/lang/Compiler.cljs, clojure/lang/Compiler.cljc, or Closure namespace "" at line 49 schema/utils.clj
              ⬆
WARNING: Use of undeclared Var clojure.lang.Compiler/CHAR_MAP at line 49 schema/utils.clj
                                       ⬆
WARNING: Use of undeclared Var schema.utils$macros/class at line 64 schema/utils.clj
            ⬆
WARNING: Use of undeclared Var schema.utils$macros/print-method at line 95 schema/utils.clj
               ⬆
WARNING: Use of undeclared Var schema.utils$macros/print-method at line 96 schema/utils.clj
            ⬆
WARNING: Use of undeclared Var schema.utils$macros/print-method at line 116 schema/utils.clj
               ⬆
WARNING: Use of undeclared Var schema.utils$macros/print-method at line 117 schema/utils.clj
                                                   ⬆
WARNING: No such namespace: java.util.Collections, could not locate java/util/Collections.cljs, java/util/Collections.cljc, or Closure namespace "" at line 141 schema/utils.clj
                                                   ⬆
WARNING: Use of undeclared Var java.util.Collections/synchronizedMap at line 141 schema/utils.clj
                         ⬆
WARNING: Use of undeclared Var schema.utils$macros/class? at line 147 schema/utils.clj
                                                                                 ⬆
WARNING: Use of undeclared Var schema.utils$macros/class at line 148 schema/utils.clj
ERROR in file schema/utils.clj
	 (new)
	 Function.cljs.core.ex_info.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:1935:200)
	 Function.cljs.analyzer.error.cljs$core$IFn$_invoke$arity$3 (NO_SOURCE_FILE <embedded>:2482:92)
	 (NO_SOURCE_FILE <embedded>:5947:100)
	 z (NO_SOURCE_FILE <embedded>:5948:13)
	 (NO_SOURCE_FILE <embedded>:5942:232)
	 (NO_SOURCE_FILE <embedded>:5862:482)
	 Object.cljs.js.load_macros (NO_SOURCE_FILE <embedded>:5838:464)
	 (NO_SOURCE_FILE <embedded>:5857:20)
	 Object.cljs.js.load_macros (NO_SOURCE_FILE <embedded>:5838:464)

No protocol method IMultiFn.-add-method defined for type undefined: 
	 Object.cljs.core.missing_protocol (NO_SOURCE_FILE <embedded>:179:229)
	 cljs.core._add_method (NO_SOURCE_FILE <embedded>:1841:468)
	 (evalmachine.<anonymous>:272:23)
	 ContextifyScript.Script.runInThisContext (vm.cljs:44:33)
	 Object.runInThisContext (vm.cljs:116:38)
	 (Object.lumoEval)
	 lumo.repl.caching_node_eval (NO_SOURCE_FILE <embedded>:6211:68)
	 (NO_SOURCE_FILE <embedded>:5947:29)
	 z (NO_SOURCE_FILE <embedded>:5948:13)
	 (NO_SOURCE_FILE <embedded>:5942:232)

iku00088804:08:11

I was testing out calvin and have a pretty tiny repro, if there is interest.

wparker15:08:20

@iku000888 supporting self-hosted ClojureScript in Clara isn’t something we’ve looked at to my knowledge, and I would anticipate that changes would need to be made to support it. If anyone has gotten that to work it would be interesting to know though. From the looks of your errors Schema has some problems with self-hosted ClojureScript as well, so there might need to be changes there as well for self-hosted CLJS Clara to work. Feel free to log an issue to Clara and anyone who wants to look at what that would take is welcome to do so. It would be nice to have, it just hasn’t been a priority. I canof how Schema would approach any problems with self-hosted ClojureScript in their codebase,

wparker15:08:24

I can’t speak to how Schema would approach any problems with self-hosted ClojureScript in their codebase, and I don’t know if there have been any previous discussions on the subject, but in my observation they’ve been pretty open to PRs, issues, etc. in the past

iku00088815:08:27

@wparker thanks for the feedback!

iku00088815:08:34

Will log an issue on the clara repo and schema (after checking they have an issue on self host)

iku00088815:08:28

Would be super cool if self host support lands though, just saying 🙂

iku00088815:08:50

@wparker Is there is anything else I can provide?

wparker15:08:42

that works thanks @iku000888

iku00088815:08:53

Thanks again!

wparker15:08:11

There would need to be some changes to Clara as well for this, not just Schema. A quick one that jumps out is that clara.rules.compiler is a clj file and has a java.beans.PropertyDescriptor import

wparker15:08:55

That’s the compiler from rules/queries to an executable structure

mikerod20:08:38

@enn I’ll add on more possibility to this: > Can an accumulator accumulate across more than one fact type (joined on some field)? All of the examples show only a single fact type in the :from clause. You can also “wrap” multiple types of facts in a common fact type and accumulate instead on that.

mikerod20:08:54

without a need of actually creating a real ancestor, hierarchical change

mikerod20:08:28

(defrecord CommonWrap [wrapped])

(r/defrule wrap-fact-a
[?a <- FactA]
=>
(r/insert! (->CommonWrap ?a)))

(r/defrule wrap-fact-b
[?b <- FactB]
=>
(r/insert! (->CommonWrap ?b)))


(r/defrule accum-them
[?acc <- my-accumulator :from [CommonWrap]]
<etc>
=>
<rhs>)

mikerod20:08:10

the accumulator could just access the original, field “x”, like (-> w :wrapped :x)

mikerod20:08:29

or you could make it have the same fields as the original even with

(r/insert! (->CommonWrap ?a))

mikerod20:08:47

> There would need to be some changes to Clara as well for this, not just Schema. Yeah, I think clara.rules.compiler would probably require the most work on self-hosting

mikerod20:08:57

(aside from schema breaking clara anyways)

mikerod20:08:07

unless there is a way to just not use the schema on the self-host side

mikerod20:08:27

I think technically, the schema are just used for testing and documentation purposes

mikerod20:08:34

but wouldn’t be too trivial I don’t think still

mikerod20:08:47

Also, the “durability” feature of Clara would likely have trouble

mikerod21:08:01

but may not be needed anyways and probably could just be skipped for that sort of build