Re: adding a member to a set in a map in a map in a map in a ref

2009-07-05 Thread Rowdy Rednose
You're right, the scenario that I described doesn't need it. In my actual code I need it because the function actually reads #(conj (or % #{}) constraint#) If I don't do that, I get a list instead of a set. On Jul 5, 5:12 pm, Meikel Brandmeyer wrote: > Hi, > > Am 05.07.2009 um 07:27 schrieb Row

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-05 Thread Meikel Brandmeyer
Hi, Am 05.07.2009 um 07:27 schrieb Rowdy Rednose: user=> (dosync (alter gnu-rms update-in [:key1 :key2 :key3] #(conj % "foo"))) {:key1 {:key2 {:key3 #{"foo" You actually don't need the anonymous function... (dosync (alter gnu-rms update-in [:key1 :key2 :key3] conj "foo")) Sincerely M

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
On Jul 5, 1:20 pm, Adrian Cuthbertson wrote: > (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) > {:key1 {:key2 {:key3 "foo"}}} I just found update-in, which is even better, as I want to update a set: user=> (def gnu-rms (ref {:key1 {:key2 {:key3 #{)) #'user/gnu-rms user=> (dosync

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
On Jul 5, 1:23 pm, Richard Newman wrote: > However, I'd point out that: > > * This might be a sign that you're doing things 'wrong'. Could be. I'm still figuring out how to do things the functional way. The reason I have these nested maps is to give my data structure. I don't want to have a loos

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
Much better! Thanks. On Jul 5, 1:20 pm, Adrian Cuthbertson wrote: > You could use assoc-in... > > (def rms (ref {:key1 {:key2 {:key3 #{)) > > (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) > {:key1 {:key2 {:key3 "foo"}}} > > Rgds, Adrian. > > On Sun, Jul 5, 2009 at 6:07 AM, Rowdy Re

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Richard Newman
Rowdy, > Do I really have to assoc all the way through to the inner map? Isn't > there a more succinct way to write this? In Common Lisp there's (setf > (getf ...)) Remember, Clojure's data structures are immutable. You're not adding a value to a set -- what you're describing is (in Clojure) a

Re: adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Adrian Cuthbertson
You could use assoc-in... (def rms (ref {:key1 {:key2 {:key3 #{)) (dosync (alter rms assoc-in [:key1 :key2 :key3] "foo")) {:key1 {:key2 {:key3 "foo"}}} Rgds, Adrian. On Sun, Jul 5, 2009 at 6:07 AM, Rowdy Rednose wrote: > > Say I have a data structure like this > > (def ref-map-map-map-set

adding a member to a set in a map in a map in a map in a ref

2009-07-04 Thread Rowdy Rednose
Say I have a data structure like this (def ref-map-map-map-set (ref {:key1 {:key2 {:key3 #{)) If I want to add a new member to the set which is the value of :key3, I currently do this: (dosync (let [key1 (:key1 @ref-map-map-map-set) key2 (:key2 key1) key3 (:key3 key2)] (re