Re: defrecord and map

2013-03-24 Thread Stephen Compall
On Sun, 2013-03-24 at 10:32 -0700, N8Dawgrr wrote: > Is there a mechanism in Clojure to say apply f to all the values of a > record and return me a new record of the same type? You can add one via the wonderful `into' function: (into your-record (map (fn [k v] [k (f v)]) your-record)) -- Steph

defrecord and map

2013-03-24 Thread N8Dawgrr
Hi, I'm transforming a recursive form structure to an equivalent structure represented by Clojure records. I want polymorphic dispatch across my newly created structure of records. I also want to be able to apply a function to transform the structure of records, in much the same way as say clo

Re: defrecord and map equality?

2010-08-04 Thread Rich Hickey
On Jul 29, 11:51 pm, Ryan Twitchell wrote: > Hi all, > > I noticed (with a very recent git pull) the following asymmetric > behavior regarding = and records: > > (defrecord my-record [a]) > > (def r (new my-record 1)) > (def s (new my-record 1)) > > (= r s)        ;; true > (= s r)        ;; tru

Re: defrecord and map equality?

2010-07-30 Thread Nicolas Oury
On Fri, Jul 30, 2010 at 4:51 AM, Ryan Twitchell wrote: > > (= r s)        ;; true > (= s r)        ;; true > (= r {:a 1})   ;; false > (= {:a 1} r)   ;; true > > Is this intentional? (I hope not) > The three first are documented in (doc defrecord) "In addition, defrecord will define type-and-valu

Re: defrecord and map equality?

2010-07-30 Thread Frederick Polgardy
I'm sure it's not intentional, but it makes sense. In the first case, the comparison delegates to `r`'s equals() method, which would return false because {:a 1} isn't a `my-record`. In the second case, the comparison delegates to `{:a 1}`'s equals() method, which is a PersistentArrayMap, which w

defrecord and map equality?

2010-07-29 Thread Ryan Twitchell
Hi all, I noticed (with a very recent git pull) the following asymmetric behavior regarding = and records: (defrecord my-record [a]) (def r (new my-record 1)) (def s (new my-record 1)) (= r s);; true (= s r);; true (= r {:a 1}) ;; false (= {:a 1} r) ;; true Is this intentio