Fork me on GitHub
#clara
<
2017-02-01
>
mikerod15:02:18

@apbleonard Think of it as clara.rules/mk-session accepts any number of “rule sources”. This can be anything that implements the clara.rules.compiler/IRuleSource protocol or just a collection of rule/query structures.

mikerod15:02:35

Clojure’s Symbol implements the clara.rules.compiler/IRuleSource protocol. The function to implement is clara.rules.compiler/load-rules which must return a collection of rule/query structures.

mikerod15:02:12

However, Will had a good example if all you want to do is something simple like pass rules in

mikerod15:02:59

(defrule one-rule <etc>)
(defrule another-rule <etc>)
(defquery some-query <etc>)

;;;; Make session
(mk-session [one-rule another-rule some-query])

mikerod15:02:41

you can also mix and match. Symbol implements IRuleSource by expecting the symbol to resolve to a namespace name. It scans the whole namespace and finds all rules/queries in vars of that namespace.

mikerod15:02:39

(mk-session [one-rule another-rule some-query] 'some.ns.with.rules)

mikerod15:02:19

@mike1452 Will mentioned that records allow you to refer to record fields directly in the rule. For non-records, you can use destructuring though. Just so you kmow

(defrule my-rule [:my-type-thing [{:keys [x y]}] (= x “hello”)] 
<etc>)

mikerod15:02:43

There should probably be documented examples of that sort of destructuring.