clara

http://www.clara-rules.org/
jdt 2018-06-01T16:01:57.000361Z

My basic problem is that I have a number of situations I would describe as "if some situation holds, insert this fact once and only once". I am unable to find a way to do this. Will post another comment with more discussion.

jdt 2018-06-01T16:09:35.000722Z

So thanks to all for the help so far, but unless I can solve this "if some fact insert this other fact ONCE" problem I'm about ready to throw in the towel. It's really like I want each rule firing to be sensitive to the prior rule firings in a single call to (fire-rules), but that isn't what happens.

zylox 2018-06-01T16:12:50.000365Z

you absoultely are fighting the engine if you do an insert-unconditional based on an inference, but still want logical retractions. Why are you using unconditional again? i havent followed all the conversations.

jdt 2018-06-01T16:13:26.000687Z

that's just one way to do it, but it wouldn't work because that rule is going to fire twice and both firings will NOT see the Derived asserted by the first firing

jdt 2018-06-01T16:13:45.000598Z

So it's not even about truth maintenance so much as WHEN the LHS is evaluated

zylox 2018-06-01T16:14:00.000176Z

oh..hmm

jdt 2018-06-01T16:15:35.000305Z

I'm open to any reasonable way to do it, but given LHS matching those two facts I inserted, the result needs to be ONE derived.

zylox 2018-06-01T16:15:43.000064Z

I guess i dont understand why you need it only inserted once and not that the final state is one in the session.

zylox 2018-06-01T16:15:59.000790Z

because you are going to absolutely end up with two if you are using unconditional

2018-06-01T16:16:19.000440Z

@dave.tenny Introduce an intermediate type that can be duplicated. De-duplicate it, aka “merge” duplicates, in a separate rule. All rules downstream of the merge won’t know the difference.

jdt 2018-06-01T16:16:23.000579Z

Maybe all I need to do is replace the [Fact (= ?ftype ftype)] with use of an accumulator and predicate to express the "if there is some", and fire the rule once, haven't tried that

jdt 2018-06-01T16:16:49.000175Z

Can you give a sample of the merge logic?

jdt 2018-06-01T16:17:02.000744Z

Oops, I see you did, I think

2018-06-01T16:17:05.000573Z

the rules don’t assume what a “duplicate” means to you or what you want to do with them. You need an extra rule to configure that yourself.

2018-06-01T16:17:23.000209Z

Example, Maybe you wanted to know how many duplicates you had

2018-06-01T16:17:40.000526Z

you could then have (defrecord Derived [ftype matches-count])

2018-06-01T16:18:04.000491Z

Then

(defrule merge-derived
  [?all <- (acc/all) :from [::derived-intermediate (= ?ftype (-> this :derived :ftype))]]
  =>
;; Merging to one, but include the count of the "duplicates" for whatever reason
  (insert! (-> ?all first :derived (assoc :matches-count (count ?all))))

jdt 2018-06-01T16:18:50.000617Z

ok, digesting this, back to drawing board

2018-06-01T17:02:38.000165Z

@dave.tenny Yep, I don’t see a reason for it there

2018-06-01T17:02:46.000726Z

I didn’t use it in the merge-derived rule either

jdt 2018-06-01T18:14:25.000130Z

That use of with-meta and :type is interesting to know about when doing type based dispatches.

jdt 2018-06-01T18:14:36.000020Z

Interesting tip

jdt 2018-06-01T18:29:06.000557Z

Anbody got an emacs cider clojure mode switch to adjust LHS condition indentation? My clauses don't seem to want to indent to the level of the prior clause.

jdt 2018-06-01T18:29:25.000615Z

Rather, bindings/predicates, not the clauses.

2018-06-01T19:33:11.000524Z

I don’t have special indentation rules

2018-06-01T19:33:20.000335Z

it indents less than ideal for vectors I’d say

2018-06-01T19:33:25.000424Z

I’ve mostly just let it happen

2018-06-01T21:50:23.000331Z

@dave.tenny I agree it isn’t ideal

2018-06-01T21:50:51.000140Z

for multiline, I typically go with:

[WorkerViableJob 
    (= ?user-id user-id)
    (= ?job-type job-type)]

alex-dixon 2018-06-01T22:05:56.000111Z

Clojure in general I find it helps to just give up on making lines short

alex-dixon 2018-06-01T22:08:07.000196Z

Most rules I’ve written have positional syntax so everything on one line works well…joins typically line up nicely. In Clara I’d probably do the same for the same reason…try to group things vertically by joins