clara

http://www.clara-rules.org/
ethanc 2020-07-09T14:12:48.204100Z

The def itself isn’t special, its just handed off to the mk-session call. Unless I am miss interpreting your question

2020-07-09T14:16:06.204700Z

@matthew.pettis I think I don’t know exactly what you are asking either, but perhaps you are just trying to understand what the ancestors fn does?

2020-07-09T14:16:18.205Z

it takes a type, and returns a set of ancestors

2020-07-09T14:16:55.205700Z

And in rules, a type T matches any rule type that is the same type T or any ancestor in the set of ancestors of T - as returned from ancestors fn

2020-07-09T14:17:36.206100Z

the docs http://www.clara-rules.org/docs/fact_type_customization/ here seem to explain this with an example though - so not sure this is where you the confusion is

2020-07-09T14:18:38.207300Z

> I get that a map can work in the function position, and will look up the value for a key given as argument, but I am struggling to see how this def works as a function to look up ancestors. A map is a fn of 1 argument. It looks no different from the callers perspective. So the clara-rules engine has a fact with type T, it looks up ancestors like: (ancestors-fn T) which returns the ancestor types

2020-07-09T14:19:41.208Z

in pure clj with the above example:

(let [ancestors-fn {:precise-temperature-reading #{:temperature-reading}}]
  (ancestors-fn :precise-temperature-reading))
;;= #{:temperature-reading}}

Matthew Pettis 2020-07-09T14:51:54.212800Z

@mikerod Thanks, I think that what you said is enough for me. The missing thing for me, which I understand from your code snipped, is that it interacts with the fact-type-function. That is, it seems that first the fact-type-function is used to get a value, and then that value (like :precise-temperature-reading), and then that is the argument to the ancestor-fn, which returns a set of ancestors that the argument belongs to, and then rules that use any of those ancestors are considered. I was trying to figure out how that ancestor-fn could be applied directly to the the fact, instead of the result of the fact-type-function applied to the fact.

Matthew Pettis 2020-07-09T14:52:43.213700Z

So, in short, I was missing that ancestor-fn operated on the result of fact-type-fn, not on the original fact itself, which I couldn't see how that would work.

2020-07-09T15:05:14.213900Z

yes exactly!

👍 1