Re: Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-24 Thread Matching Socks
In case it's not clear from the above, {:keys [...]} is a 
technique for *map* destructuring of associative data structures.

(let [{:keys [a b]} {:a 1 :b 2}] [a b])
[1 2]


As documented at http://clojure.org/reference/special_forms, :keys
takes a vector of the symbols to bind.

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-23 Thread Nicola Mometto
that's an implementation detail you should not rely on.
it only works to support keyword arguments to functions
On 23 Jan 2016 17:36, "Harold"  wrote:

> Hello,
>
> While destructuring yesterday, I encountered this difference:
>
> > (let [{:keys [:a :b]} '(:a 1 :b 2)] [a b])
> [1 2]
>
> > (let [{:keys [:a :b]} [:a 1 :b 2]] [a b])
> [nil nil]
>
> I have read some of the relevant documentation and some related blog
> posts, but I am still having trouble explaining this difference
> (destructuring seems to work with PersistentList and not with
> PersistentVector).
>
> Kind thanks in advance for any insight.
>
> Warmly,
> -Harold
>
> --
> 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
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-23 Thread Gregg Reynolds
On Jan 23, 2016 11:36 AM, "Harold"  wrote:
>
> Hello,
>
> While destructuring yesterday, I encountered this difference:
>
> > (let [{:keys [:a :b]} '(:a 1 :b 2)] [a b])
> [1 2]
>
> > (let [{:keys [:a :b]} [:a 1 :b 2]] [a b])
> [nil nil]
>
> I have read some of the relevant documentation and some related blog
posts, but I am still having trouble explaining this difference
(destructuring seems to work with PersistentList and not with
PersistentVector).

The keys of a vector are ints.  In your second example, :a and :b are
values, not keys.

Gregg

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Destructuring seems to work with PersistentList and not with PersistentVector

2016-01-23 Thread Harold
Hello,

While destructuring yesterday, I encountered this difference:

> (let [{:keys [:a :b]} '(:a 1 :b 2)] [a b])
[1 2]

> (let [{:keys [:a :b]} [:a 1 :b 2]] [a b])
[nil nil]

I have read some of the relevant documentation and some related blog posts, 
but I am still having trouble explaining this difference 
(destructuring seems to work with PersistentList and not with 
PersistentVector).

Kind thanks in advance for any insight.

Warmly,
-Harold

-- 
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
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.