Fork me on GitHub
#clara
<
2017-05-26
>
puzzler09:05:27

Can someone point me to documentation about how to construct clara rules dynamically?

nkabrich11:05:05

AFAIK defrule just generates a data structure so you can either build that by hand dynamically or check out clara.rules.dsl/parse-rule

wparker14:05:05

@puzzler There are a number of examples of dynamic rule creation in https://github.com/cerner/clara-rules/blob/master/src/test/clojure/clara/test_rules.clj You can also just build the rule data structures yourself if that is more convenient for your use-case; see the schema at https://github.com/cerner/clara-rules/blob/master/src/main/clojure/clara/rules/schema.clj#L62

wparker14:05:34

You’ll need to fully qualify reference in your LHS (left-hand side) code if you use that approach, although in the RHS code it will evaluated in the ns you give if you give one as noted in the comment on the schema; that would be good to do in the LHS too, it just hasn’t been implemented yet

ryanbrush14:05:13

There is also an example of generating rules from an external DSL on this blog post. Towards the bottom you'll see the Clojure data structure that defines the rules themselves. http://www.toomuchcode.org/blog/2015/11/14/insta-declarative-dsls/

ryanbrush14:05:09

But often just writing defrule for your rules, then looking at the data structure it creates can give you a good idea of what you need, as @nkabrich suggests.