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


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?


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


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).


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


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


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


@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)]]


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.


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