The union core.logic matches the value on the map, but not the key

I do not understand why, from the following two examples, the first returns the correct value (1) , and the second returns () . I was expecting a result (:key) or an exception that cannot find a 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})) 
+5
source share
1 answer

I did not find it documented as the intended behavior or not, but, looking at the source code , from my (limited) understanding, it looks like map merging happens only with values, and not with keys.

As implemented in unify-with-map* , when core.logic finds the key :key on the first map, it looks at its value in the second, does not find it, and is thus freed when merged. Since there are no solutions like @Arthur Ulfeldt, you get () .

+3
source

Source: https://habr.com/ru/post/1208461/


All Articles