the other day i asked about how to audit which query rules are satisfied and favila had a nice suggestion to use ground
to return some known value. that works when my "top level" rule returns a grounded value, however i'd like to also audit nested rules as well. any idea how i can aggregate some grounded values from each rule?
here is a non-working example that returns an empty result because i think the bound value of ?rule
in the parent rule fails to unify on the different bound values in the nested rules.
(let [rules '[[(is-blue ?item ?rule)
[(ground :is-blue) ?rule]
[?item :item/color "blue"]]
[(is-in-stock ?item ?rule)
[(ground :is-in-stock) ?rule]
[?item :item/inStock? true]]
[(blue-items-in-stock ?item ?rule)
[(ground :blue-items-in-stock) ?rule]
(is-blue ?item ?rule)
(is-in-stock ?item ?rule)]]]
(d/q '{:find [?item (distinct ?rule)]
:in [$ %]
:where [(blue-items-in-stock ?item ?rule)]}
(d/db conn) rules))
=> []
ideally i would end up with something like this:
=> [[92358976734084 #{:blue-items-in-stock :is-blue :is-in-stock}]]
well this is exactly what i was looking for. thank you @lanejo01!
NP, I just wish I would have thought of it sooner 😂 . Definitely could have used this over the years.
> [?item :item/inStock? true ?rule]
is that 4th element intended?
oops, that was just a typo in the example. thanks for pointing it out.