-
Notifications
You must be signed in to change notification settings - Fork 271
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document destructuring of singleton map sequences #688
Comments
here are some relevant threads on clojurian slack highlighting the confusion: https://clojurians.slack.com/archives/C03S1KBA2/p1668533720466509 https://clojurians.slack.com/archives/C03S1KBA2/p1707982404402549 https://clojurians.slack.com/archives/C03S1KBA2/p1714580544135239 https://clojurians.slack.com/archives/C03S1KBA2/p1715935559111129 |
I just tripped over this issue today too. i thought it's a bug, but @puredanger said it's intended behaviour: so the it provides this example: (defn configure [val & {:keys [debug verbose]
:or {debug false, verbose false}}]
(println "val =" val " debug =" debug " verbose =" verbose)) so it should mention how it behaves the same way, as a function defined as: (defn configure [val {:keys [debug verbose]
:or {debug false, verbose false}}]
(println "val =" val " debug =" debug " verbose =" verbose)) when called as im not sure what reasoning can be given for this behaviour though... Ponderinggiven this situation: (let [m {:x 1}
{itself :x} m
{from-list :x} (list m)
{from-list-of-2 :x} (list m m)
{from-vector :x} (vector m)]
[(= itself from-list)
(nil? from-list-of-2)
(not= from-list from-vector)]) i'd say
in my specific situation the behaviour was even more magical, because i had function with an optional argument after the map destructuring one: |
Since clojure 1.11 (as per CLJ-2603), destructuring a sequence containing a single map can directly bind to the map contents. An example of this can be seen here. It might be a good idea to mention this in the destructuring guide as this behaviour might be surprising to some (at least it was for me).
The text was updated successfully, but these errors were encountered: