This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-12-06
Channels
- # adventofcode (181)
- # aws (6)
- # beginners (112)
- # boot (38)
- # cider (11)
- # cljs-dev (12)
- # cljsrn (2)
- # clojure (187)
- # clojure-greece (31)
- # clojure-italy (19)
- # clojure-new-zealand (1)
- # clojure-poland (1)
- # clojure-spec (20)
- # clojure-uk (114)
- # clojurescript (97)
- # core-logic (25)
- # cursive (3)
- # data-science (17)
- # datascript (3)
- # datomic (23)
- # defnpodcast (1)
- # duct (5)
- # emacs (3)
- # fulcro (299)
- # graphql (108)
- # jobs (1)
- # juxt (4)
- # lein-figwheel (7)
- # leiningen (1)
- # lumo (9)
- # nrepl (2)
- # off-topic (10)
- # om (2)
- # onyx (36)
- # pedestal (1)
- # perun (3)
- # re-frame (14)
- # reagent (12)
- # ring (2)
- # rum (11)
- # shadow-cljs (6)
- # spacemacs (4)
- # unrepl (8)
is there a rationale for why lvars as map keys do not unify?
(run* [q]
(fresh [a b]
(== {a b} {:a 2})
(== q (list a b))))
;; => ()
in my spare time i’ve been working on a term rewriting engine and was also confronted with the problem of unifying maps. i was able to find a solution that achieves this. i was surprised to find that core.logic
doesn’t support this, however, i wouldn’t be surprised if i may have overlooked something in my own algorithm.
the algorithm i wrote unifies ground entries, then entries with ground values, then entries with ground keys, then entries where both the key and value are variable.
your example can be unified in multiple ways, the values can be streamed to a, b, c, and d in those cases.
lists are defined inductively via cons, so there is a one order they can be walked for unification, and that orders arises from the definition
maps are not inductively defined, so there is no single iteration order, so there is no fixed thing to wire in to the unifier
you can do it, but you will have to make some choices to do it that preclude being general, which is what a library like core.logic is trying to do
i’m guessing the solution here would be to use another goal in favor of ==
which does stream the substitutions.
because unification has to traverse datastructures, if a datastructure is defined inductively, that is an order the structure can be traversed
I bet you could make it work if you either only used one concrete map type, or sorted it before unifying
the strategy i mentioned above works pretty well. although, again, my setting is term rewriting which expects the left-hand side of the equation to be ground.