clara

http://www.clara-rules.org/
tony.kay 2018-06-25T17:58:16.000553Z

Hi, is it ok to use *current-session*? it isn’t documented, but it would be handy to run queries during rule execution…or is that just a bad idea?

2018-06-25T18:30:13.000686Z

@tony.kay sounds like a bad idea 😛

2018-06-25T18:30:26.000775Z

Are you wanting to use it for debugging or for more than that?

tony.kay 2018-06-25T18:31:14.000736Z

So, we have facts that are stored in a datomic-fashion…so “insert” needs to know if the fact (as an E/A pair) is already present so we can retract the old value before inserting the new one

2018-06-25T18:31:30.000141Z

The thing is (a) it isn’t documented/impl detail, so would be subject to breaking changes (b) but even more worrisome is that there isn’t any strong guarantees about rules firing order or if a rule will be fired/retracted/re-fired etc So arbitrarily looking into the *current-session* could cause problems

tony.kay 2018-06-25T18:31:33.000077Z

so, we need to know what is in the current session

tony.kay 2018-06-25T18:32:01.000657Z

yeah, I understand that, but rule firing order doesn’t matter in that case…I need to know if a fact is in there right as that rule fires

2018-06-25T18:32:16.000233Z

I think that http://www.metasimple.org/2017/12/23/clara-updating-facts.html relates to this concept of safely “updating” facts

2018-06-25T18:32:28.000265Z

although it doesn’t provide an ideal solution

2018-06-25T18:33:28.000349Z

You can use things like insert-unconditional! and also :no-loop properties on a defrule to attempt to do things like you are describing. However, I try to avoid those since they become more imperative/order-dependent etc in nature. Also, they can have interactions at odds with the rest of the truth maintenance system.

2018-06-25T18:33:52.000616Z

In the post linked above, I mention “Approach 1: Append only updates”

2018-06-25T18:34:10.000220Z

that’s the easiest, but can run up against memory limits depending on how you are using things

2018-06-25T18:35:19.000314Z

I didn’t explain in that post, but I think the “Approach 1: Append only updates” could be extended to have an external process/fn that cleans up old UpdatingFactSnapshot later (using a query to access them externally).

tony.kay 2018-06-25T18:37:08.000021Z

cool, thanks. I’ll read the article. I’m sure I’m missing somehting about the TMS that I’m not clear on 🙂 Hopefully that’ll get me squared up

tony.kay 2018-06-25T19:01:29.000066Z

@mikerod so, in the project I’m helping with, they are not using the logic tracking facility…so invalidating a truth does not auto-retract anything. Perhaps this is a problem that should be addressed as well, but does that affect your answer at all?

tony.kay 2018-06-25T19:01:58.000381Z

(e.g. they are using unconditional inserts)

tony.kay 2018-06-25T19:02:22.000529Z

oh, I guess you mentioned that…unconditional

2018-06-25T19:02:36.000385Z

If you use unconditional inserts, those rules will rely on order of firing

tony.kay 2018-06-25T19:02:39.000369Z

I lost track while reading the article 😜

2018-06-25T19:02:47.000615Z

since the rules won’t try to “correct” for inconsistencies if a rule fires in the “wrong order”

2018-06-25T19:03:13.000534Z

but if you are opting out of truth maintenance, then yeah, you can do unconditional things

tony.kay 2018-06-25T19:03:41.000239Z

ok, I’ll try to get to the bottom of why they want to opt-out as well

tony.kay 2018-06-25T19:03:56.000781Z

I agree it would be nice to reason about things in isolation

2018-06-25T19:04:56.000391Z

(defrule udpate-it
  [?old-one <- A (= ?e e) (= ?a a)]
  [?new-one <- NewA (= ?e e) (= ?a a)]
  =>
  (retract! ?old-one)
  (insert-unconditional! (map->A ?new-one)))

2018-06-25T19:05:07.000628Z

I’d worry a bit about pervasive use of unconditional inserts

2018-06-25T19:05:33.000028Z

it misses out on one fairly large advantage of the rules engine - which is a declarative logical truth maintenance system.

2018-06-25T19:05:58.000196Z

If unconditional is used, it’d be best to a least to try to isolate it to some fringe “layer” of the logic

tony.kay 2018-06-25T19:16:44.000518Z

yeah, these are more derived new facts…but I see your point about invalidating the condition of the rule you’re running