Oh, wait, my bad... you're getting the keyword args special
destructuring. i.e., you're telling Clojure to expect a map and store
the appropriate keys in the proper symbols
user=> ((fn [{:keys [k]}] (str k)) {:k "Awesome" :l "Beer"})
"Awesome"
user=> ((fn [{:keys [k l]}] (str k l)) {:k "Awesome" :l "Beer"})
"AwesomeBeer"
Not 100% why you're having an issue, gotta think.
On Apr 30, 2:56 pm, Russell Christopher
<[email protected]> wrote:
> Why does this work?
> (defrecord R [k])
> (extend-protocol P R (p [{:keys [k]}] k))
>
> On Fri, Apr 30, 2010 at 2:52 PM, Sean Devlin <[email protected]>wrote:
>
>
>
> > I think you have your destructuring backwards.
>
> > You fn should probably be (fn [{k :keys}] k)
>
> > For example,
>
> > user=> ((fn [{k :keys}] k) {:keys "Awesome"})
> > "Awesome"
>
> > On Apr 30, 2:46 pm, russellc <[email protected]> wrote:
> > > Should this compile?
>
> > > (defprotocol P (p [this]))
> > > (defrecord R [k] P (p [{:keys [k]}] k))
>
> > > java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot
> > > be cast to clojure.lang.Symbol
>
> > > --
> > > You received this message because you are subscribed to the Google
> > > Groups "Clojure" group.
> > > To post to this group, send email to [email protected]
> > > Note that posts from new members are moderated - please be patient with
> > your first post.
> > > To unsubscribe from this group, send email to
> > > [email protected]<clojure%[email protected]>
> > > For more options, visit this group athttp://
> > groups.google.com/group/clojure?hl=en
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to [email protected]
> > Note that posts from new members are moderated - please be patient with
> > your first post.
> > To unsubscribe from this group, send email to
> > [email protected]<clojure%[email protected]>
> > 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 post to this group, send email to [email protected]
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group
> athttp://groups.google.com/group/clojure?hl=en
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en