We're updating the issue view to help you get more done. 

:or defaults should refer to enclosing scope in map destructuring

Description

Michael Blume noticed that :or defaults can depend on the values of other keys, see https://groups.google.com/d/msg/clojure/6kOhpPOpHWM/ITjWwQFS_VQJ

Michael's Gist https://gist.github.com/MichaelBlume/4891dafdd31f0dcbc727 displays a case where an associative form involving :keys and :or compiles or not depending on the order of symbols in :keys. By tweaking that case one can arrive at expressions which always compile, but produce different values depending on :keys:

1 2 3 4 5 6 7 8 9 10 11 12 13 (let [foo 1 bar 2 {:keys [bar foo] :or {foo 3 bar (inc foo)}} {}] {:foo foo :bar bar}) ;= {:foo 3, :bar 4} (let [foo 1 bar 2 {:keys [foo bar] :or {foo 3 bar (inc foo)}} {}] {:foo foo :bar bar}) ;= {:foo 3, :bar 2}

I believe that the most natural solution is to demand that :or defaults be evaluated in an enclosing scope where none of the destructuring-introduced locals are present. This approach is taken by the 0001 patch.

Environment

None

Status

Assignee

Michał Marczyk

Reporter

Michał Marczyk

Labels

Approval

Triaged

Patch

Code and Test

Priority

Minor