Clojurians
#clara
<
2018-01-29
>

This page is not created by, affiliated with, or supported by Slack Technologies, Inc.

tcarls01:01:06

If I have records having a field used for ordering -- like a timestamp -- and want to make rules that reason about or refer to "the immediately preceding X", or "the most recent X to have attribute Y", is Clara well-suited to the purpose?

tcarls01:01:34

("immediately preceding" relative to another record, that is, as opposed to, say, an accumulator reflecting the globally most recent insert/assertion).

dadair02:01:32

It can be, I’m currently using it to reason about entities that change over time. I have to admit though that I don’t find it that easy to model (although I could be doing things horribly wrong).

dadair02:01:02

e.g., I have entities of type A that can change over time (tracked through a timestamp), and other entities of type B that can change over time in response to the changes to type A (that is, there is a relation B = f(A)), and other entities of type C = f(B) that also change over time in response to changes in B

dadair02:01:06

I find the rules I’m writing to be quite.. cumbersome, and I find myself inserting special facts just to facilitate rule propagation, to prevent e.g., infinite activations

dadair02:01:05

however, the challenges I face come from the /fact/ that changes are inserted as a consequence of rules, if all history was known prior to rule activation, and I wasn’t inserting new facts from rules (that is, growing/extending time within a given session’s fire-rules), and I was simply querying certain states throughout a known and unchanging history, that would be perfectly suitable

mikerod15:01:47

@tcarls I think that @dadair has some good things to think about in terms of what you are trying to accomplish. Some of it varies according to the situation. Here is an example that I think meets at least one part of your question though

(defrule immediately-preceding
  [A (= timestamp ?ts)]
  [?preceding <- (acc/max :timestamp :returns-fact true) :from [B (< timestamp ?ts)]]
  =>
  <etc>)

mikerod15:01:57

You can use an accumulator that constrains the facts that it accumulates over. By doing this, you can match things more specific/localized/“parameterized”, rather than “global” accumulations.

tcarls16:01:48

@mikerod, that's extremely helpful; thank you.