Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

core.logic unification matches value in map but not key

I don't understand why from the following two examples, the first one returns the correct value (1), while the second returns (). I'd have expected the result (:key) or an exception that it can't find the solution, but not an empty list.

(l/run* [q]
  (l/== {:key 1} {:key q}))

;; BUT IT DOESNT WORK

(l/run* [q]
  (l/== {:key 1} {q 1}))
like image 313
shaft Avatar asked Oct 19 '22 21:10

shaft


1 Answers

I haven't found it documented as intended behaviour or not, but looking at the source code, from my (limited) understanding, it looks like unification of maps only happens with values, not keys.

As implemented in unify-with-map*, when core.logic finds the key :key in the first map, it looks up its value in second, doesn't find it, and so bails on the unification. Since there are no solutions, like @Arthur Ulfeldt said, you end up with ().

like image 77
Beyamor Avatar answered Oct 23 '22 00:10

Beyamor