Hierarchical data core.logic

72 views
Skip to first unread message

dan.sto...@gmail.com

unread,
Nov 13, 2014, 12:26:44 PM11/13/14
to clo...@googlegroups.com
I think this is a dummy question, but wondering whether this is possible in core.logic?

Lets say I have a set of relations

(db-rel foo p)
(db-rel bar p)
(db-rel fooz p p2)

and facts
[foo 1]

[bar 2]
[fooz 2 1]

[bar 3]
[fooz 3 1]

See that the fooz relation is potentially describing bar as children of foo's. (like a foreign key)

and I want to unify with all the `bar`s for a given `foo` like so:

(run* [?q]
 (fresh [?foo ?bars] 
  (bars-for-foo ?foo ?bars)
  (l/== {:foo ?foo 
           :bars ?bars}
          ?q)))
=>

({:foo 1, :bar (2 3)})

Is it possible to define bars-for-foo?




David Nolen

unread,
Nov 13, 2014, 12:30:53 PM11/13/14
to clojure
There's no need to define the reverse relation - fooz can do it. Just
supply bar and leave the foo fresh.

David
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Daniel Stone

unread,
Nov 13, 2014, 12:53:21 PM11/13/14
to clo...@googlegroups.com
I'm not sure I fully understand, I guess I'm looking for the equivalent to a sub query? When I tried to implement this early, I naively perhaps tried something like this:

(defn bars-for-foo
  [?foo ?bars]
  (l/== ?bars
    (l/run* [?q]
      (fooz ?foo ?q))))




You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/qtqzGaHQd2k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

David Nolen

unread,
Nov 13, 2014, 1:19:09 PM11/13/14
to clojure
Ah sorry I miss read. Not currently supported, it's a requested
feature from Prolog that I haven't gotten around to implementing.

David
Reply all
Reply to author
Forward
0 new messages