Fork me on GitHub
#clara
<
2016-01-13
>
datajohnny15:01:32

hello, I been fiddling around and im stuck at this right now: https://gist.github.com/datajohnny/3b82660ba27fd80f448c

ragge15:01:00

(insert! (->Person)))

ragge15:01:10

you're calling the positional constructor for Person

ragge15:01:20

it requires two arguments, name and age

ragge15:01:25

you're only giving one

ragge15:01:42

Caused by: clojure.lang.ArityException: Wrong number of args (0) passed to: core/eval6101/->Person--6116

datajohnny15:01:51

@ragge: what I want is to add that record when the rule is true

datajohnny15:01:08

I thought I was accomplishing that in that manner

datajohnny15:01:23

do I need to pass the params in?

datajohnny15:01:17

another thing is that for some reason age the (>= 21 age) is not working if I set the age on the session to 21

ryanbrush16:01:48

@datajohnny That test rule matches a person when the age is >= 21, so it is only true if such a person has already been inserted. The right-hand side of the rule is just a Clojure s-expression that can insert additional facts derived from what matched. So typically you would insert the person (as that example does), match on age >=21, and insert a new fact if that's the case (like a PersonIsAdult fact).

ryanbrush16:01:07

@datajohnny: If you want to get an idea of general usage patterns, I'd check out the examples at https://github.com/rbrush/clara-examples/tree/master/src/main/clojure/clara/examples

datajohnny16:01:26

@ryanbrush: can the rules work with just maps instead of records, I am trying to build kinda like the same thing you had in your latest blog post but instead of grammar I am getting a json payload

ryanbrush16:01:40

@datajohnny: It can use records. You'll need to provide a function that returns a "type" for map you use, which will match the type of the rule. See the fact-type-fn at http://www.clara-rules.org/docs/expressions/#fact-expressions. There's also a unit test that shows some usage of it at https://github.com/rbrush/clara-rules/blob/master/src/test/clojure/clara/test_rules.clj#L1977. The test generates rules in place but you can see a provided fact-type-fn that just reads a field from a record in action.