Map-destructuring a non-associative structure, non documented behavior?

2012-09-24 Thread Nahuel Greco
I can't find the documentation for this behaviour:

(let [{x :b :as y} '(:a 1 :b 2)] [x y])

;= [2 {:a 1, :b 2}]

It seems as if the list in the init-expr is converted first to an
associative structure and then destructured.
But that behaviour doesn't seems to be documented, the map destructuring
documentation only talks
about destructuring of associative structures, and also there is nothing
about binding the :as expression
to the resultant associative structure instead of the initial init-expr.

Is this documented somewhere? Is an intended behaviour assured to be
present in the future Clojure
versions?

Saludos,
Nahuel Greco.

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Map-destructuring a non-associative structure, non documented behavior?

2012-09-24 Thread Ben Smith-Mannschott
On Tue, Sep 25, 2012 at 5:10 AM, Nahuel Greco ngr...@gmail.com wrote:
 I can't find the documentation for this behaviour:

 (let [{x :b :as y} '(:a 1 :b 2)] [x y])

 ;= [2 {:a 1, :b 2}]

 It seems as if the list in the init-expr is converted first to an
 associative structure and then destructured.
 But that behaviour doesn't seems to be documented, the map destructuring
 documentation only talks
 about destructuring of associative structures, and also there is nothing
 about binding the :as expression
 to the resultant associative structure instead of the initial init-expr.

 Is this documented somewhere? Is an intended behaviour assured to be present
 in the future Clojure
 versions?

TL;DR: Intentional. Since 1.2.0.

This behavior was added in Clojure 1.2.0, the changes.txt for that release says:

== 2.3 Destructuring Enhanced ==

If you associatively destructure a seq, it will be poured
into a map first:

  (defn foo [ {:keys [a b c]}]
[a b c])

  (foo :c 3 :b 2)
  = [nil 2 3]

But, I didn't see a reference to this behavior on the page on
clojure.org where special forms and destructuring are discussed [1].

[1]: http://clojure.org/special_forms#Special Forms--(let [bindings* ] exprs*)

// Ben

-- 
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en