Re: defrecord question

2010-04-30 Thread Jarkko Oranen
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

Re: defrecord question

2010-04-30 Thread Sean Devlin
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"

Re: defrecord question

2010-04-30 Thread Russell Christopher
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"})

Re: defrecord question

2010-04-30 Thread Sean Devlin
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))

defrecord question

2010-04-30 Thread russellc
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