On Apr 30, 9:46 pm, russellc 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
defrecord doesn't yet support destructuring as far as I k
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"
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 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"})
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 wrote:
> Should this compile?
>
> (defprotocol P (p [this]))
> (defrecord R [k] P (p [{:keys [k]}] k))
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 th