Fork me on GitHub
#clara
<
2017-09-25
>
enn16:09:26

I have this clause in an LHS:

[?last-performed-date <- (acc/max :date)
   :from [fact/test-result
          (= ?test-id test-id)]]
Because the initial value of the max accumulator is nil, it never fires when there are no test-result facts. Am I missing some idiomatic way to have it fire in that case? Do I need to write my own accumulator with a different initial value? Can I do this with :or?

mikerod19:09:29

@enn you should just structure the rules in a way to handle the missing case

mikerod19:09:45

since acc/max doesn’t necessarily make sense for no facts - that may not always be the behavior that was desired

mikerod19:09:08

You could give it an :initial-value if you wanted to I suppose though

mikerod19:09:45

[?last-performed-date <- (assoc (acc/max :date) :initial-value <my-date>)
   :from [fact/test-result
          (= ?test-id test-id)]]
not sure it will always be clear what happened though

enn19:09:27

@mikerod thanks--I ended up adding an [:or ... [:not [fact/test-result (= ?test-id test-id)]]]1

nickowsy21:09:48

Is there a way to use accumulate with multiple fact_contraints? For example, if I have the facts

{:e 2, :a :type, :v :dog}
{:e 2, :a :age, :v  12}
{:e 3, :a :type, :v :cat}
{:e 3, :a :age, :v 2}
{:e 4, :a :type, :v :dog}
{:e 4, :a :age, :v 10}
I would like to acc/all :type facts, matching :type is :dog and :age > 4. The :fact-type-fn is :a.

mikerod21:09:11

[:type
 (= (:v this) :dog)
 (= ?id (:e this))]

[?all <- (acc/all)
 :from [:age
        (= ?id (:e this))
        (> (:v this) 4)]
@nickowsy perhaps?

mikerod21:09:28

So an accumulator that does a join with another fact

nickowsy21:09:49

@mikerod, cool thanks. I had something similar but was seeing the rule run multiple times. Once for each

[:type
 (= (:v this) :dog)
 (= ?id (:e this))]
match

mikerod21:09:51

@nickowsy yes, it would