Fork me on GitHub
#clara
<
2020-07-09
>
ethanc14:07:48

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

mikerod14:07:06

@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?

mikerod14:07:18

it takes a type, and returns a set of ancestors

mikerod14:07:55

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

mikerod14:07:36

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

mikerod14:07:38

> 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

mikerod14:07:41

in pure clj with the above example:

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

matthew.pettis14:07:54

@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.pettis14:07:43

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.

mikerod15:07:14

yes exactly!