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}))
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 ()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With