Fork me on GitHub
#core-logic
<
2017-06-07
>
fabrao05:06:58

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?

norman15:06:11

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)

norman15:06:50

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

norman15:06:50

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

norman15:06:10

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

norman15:06:29

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

norman15:06:36

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

norman15:06:44

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

newres16:06:43

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?

fabrao21:06:41

@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

fabrao21:06:38

but that´s the idea

norman21:06:53

Sorry - i don’t understand what you want.

fabrao21:06:46

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