Fork me on GitHub

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


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


@puzzler There are a number of examples of dynamic rule creation in You can also just build the rule data structures yourself if that is more convenient for your use-case; see the schema at


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


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.


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.