<< Back to previous view

[LOGIC-72] Unification with partial-map fails when a map contains a map value with extra keys Created: 22/Nov/12  Updated: 28/Jul/13  Resolved: 23/Nov/12

Status: Closed
Project: core.logic
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Defect Priority: Major
Reporter: Hugo Duncan Assignee: David Nolen
Resolution: Declined Votes: 0
Labels: None

Attachments: File recursive-partial-map.diff    
Patch: Code and Test


Unification fails for partial-map when there is a partial match on a sub-map.

A failing test case:

(is (= '[#clojure.core.logic.PMap{:a {:b 2}}]
         (run* [q]
           (fresh [pm x]
             (== (partial-map {:a {:b x}}) pm)
             (== {:a {:b 2 :c 3}} pm)
             (== q pm)))))

Comment by Hugo Duncan [ 23/Nov/12 3:55 PM ]

As mentioned by Kevin Lynagh, this can be achieved using walk-term, and I agree the behaviour is better off being explicit.

(defn ->pmap [x]
  (if (map? x)
    (l/partial-map x)

(l/unifier target (->pmap (l/walk-term my-map ->pmap)))
Comment by David Nolen [ 23/Nov/12 3:58 PM ]

having partial-map implicitly recurse is undesirable. It's easy to achieve the desired behavior now that we have a reusable walk-term built into core.logic.

Generated at Tue Oct 17 15:40:24 CDT 2017 using JIRA 4.4#649-r158309.