clara

http://www.clara-rules.org/
PB 2020-10-16T14:40:02.065600Z

Is there a way to create rules without the defrule macro? I am currently pulling constraints out of a database and would like to make a bunch of rules based off of those. I noticed that the macro appears to just create a var?

(def
 do-it
 {:ns-name 'woof,
  :lhs '[{:type woof.Person, :constraints [(= name "me")]}],
  :rhs '(do (prn "99999")),
  :name "woof/do-it"})
However creating that var does not seem to create the rule.

PB 2020-10-16T14:43:49.067300Z

My guess is that this is not adding that var to the clara-session?

2020-10-16T14:47:26.067700Z

@petr it is supported and you don’t even need vars

2020-10-16T14:47:30.067900Z

but you can use vars if that is convenient for you

2020-10-16T14:47:51.068300Z

if you do use vars, the question then becomes how is it “auto detected” via Clara’s default namespace scanning impl

2020-10-16T14:47:56.068500Z

and that is done via metadata

PB 2020-10-16T14:50:35.070500Z

@mikerod I would use vars or not. It just feels better than using a macro to generate defrules

2020-10-16T14:50:52.071200Z

this is what it does to scan built-in

2020-10-16T14:50:53.071400Z

so specifically for vars

2020-10-16T14:50:53.071600Z

if you have meta : :rule, :query, or :production-seq

2020-10-16T14:50:53.071800Z

it is treated as a rule container of some sort

2020-10-16T14:50:54.072Z

:rule and :query are a single rule/query

2020-10-16T14:50:54.072100Z

:production-seq is a collection of rules/queries - aka “productions”

2020-10-16T14:50:54.072300Z

you don’t need macros

2020-10-16T14:50:55.072500Z

and you don’t need vars

2020-10-16T14:50:56.072700Z

if you have a more data-oriented case

2020-10-16T14:51:08.073Z

mk-session takes collections of rule/query (aka production) structures

PB 2020-10-16T14:51:13.073200Z

I'm open to really any approach here

2020-10-16T14:51:39.073700Z

well, you just have to choose what is best suited

PB 2020-10-16T14:51:47.074100Z

Oh cool. so I could actually pass those "rule" maps to the mk-session?

2020-10-16T14:51:49.074200Z

vars are awkward to create if you’re doing it like at runtime

PB 2020-10-16T14:52:31.074400Z

I agree

2020-10-16T14:52:49.074900Z

if you look at tests

2020-10-16T14:53:50.076800Z

as example

2020-10-16T14:53:51.076900Z

you see they are almost all just based on passing rule/query maps in a collection to mk-session

2020-10-16T14:53:51.077Z

so this is probably all you are really looking for

2020-10-16T14:53:51.077100Z

vars with metadata are basically just a convenience

2020-10-16T14:53:51.077200Z

for automatic rule/query detection in namespaces

2020-10-16T14:54:07.077600Z

which works better for cases where you are more statically writing rules via macros/DSL

PB 2020-10-16T14:55:55.077900Z

Ohhh that looks useful, thank you for showing me that

2020-10-16T15:43:03.078100Z

no problem

2020-10-16T15:43:16.078700Z

I looked briefly on http://clara-rules.org and do not see any actual good documentation around “rule sources”

2020-10-16T15:43:22.078900Z

which I think could be improved

PB 2020-10-16T15:43:37.079600Z

@mikerod thank you so much for that. This has made my day a lot easier

2020-10-16T15:43:40.079700Z

I think it’s lacking if we don’t include other major variants of how to load rules

2020-10-16T15:43:52.080100Z

We’ve taken special care in a lot of the clara stuff to make it where the DSL is optional

2020-10-16T15:44:11.080700Z

and to have the API accept other data-oriented options

PB 2020-10-16T15:44:22.081300Z

Yeah, this is clearly very well thought out

2020-10-16T15:44:30.081600Z

just DSL + var/ns scan-loading is built-in for convenience and the typical, most easy examples