core-logic

fabrao 2017-06-07T05:23:58.630112Z

Hello all, I have something like this [:A :B] [:A :C] [:B :C] how can I get the result [:A [:B :C]], is that possible with core.logic?

2017-06-07T15:27:11.882086Z

What exactly are you asking? Are you asking how to transform the results of your core.logic query? Or are you asking how to rewrite your core.logic query? (in which we’d need a query)

2017-06-07T15:44:50.335328Z

If it’s the former, this might get you started:

2017-06-07T15:44:50.335571Z

user> (reduce (fn [m [k v]] (update-in m [k] #(conj (or % #{}) v))) {} [[:A :B] [:A :C] [:B :C]]) {:A #{:B :C}, :B #{:C}}

2017-06-07T15:45:10.344053Z

No time to make that cleaner, but it’s something to work from

2017-06-07T15:46:29.378253Z

user> (for [[k v] *1] [k (vec v)])

2017-06-07T15:46:36.381236Z

([:A [:B :C]] [:B [:C]])

2017-06-07T15:46:44.384544Z

if you need to get it back to vectors, I guess

newres 2017-06-07T16:10:43.994436Z

Hi, is there a way to use core.logic as a kind of backward chaining rule engine? I kind of figured out that I can write a goal to encapsulate the singe execution of a rule, but how could I express that a portion of goal could be used multiple times to derive a conclusion?

fabrao 2017-06-07T21:43:41.209325Z

@norman well, I´m trying to use it like I used to use in Prolog as I remember

repetition ([X|T]) :- repetition(X,A), repetition(X,B), A != B.
I don´t know if it´s correct

fabrao 2017-06-07T21:44:38.224934Z

but that´s the idea

2017-06-07T21:45:53.245052Z

Sorry - i don’t understand what you want.

fabrao 2017-06-07T21:47:46.275478Z

🙂 ok, I´m trying to use core.logic instead of using something like http://www.clara-rules.org/