Re: atom / swap! question

2012-08-01 Thread Vinay D.E
Thanks for your replies Marshal & Jim. I had not understood the 'laziness' concept correctly and was expecting it to behave differently. I thought that this post had somehow disappeared and I started another one on the same topic. Sorry about that. --Vinay On Tuesday, 31 July 2012 18:17:00 U

Re: atom / swap! question

2012-07-31 Thread Marshall T. Vandegrift
"Vinay D.E" writes: > I am a newbie and was doing some exercises when I ran across something that > I don't understand. > I am trying to count the number of elements in an array less than 100. > > My first attempt didn't work. The counter returns 0 > > (let [a (atom 0) > i (take-while (fn[

Re: atom / swap! question

2012-07-31 Thread Dimitrios Jim Piliouras
If I understand correctly you don't need an atom to count the elements in a seqall you need is 'count' (let [s [1 2 3 4 5] n (count s)] (vector n s)) => [5 [1 2 3 4 5]] If you want to count only the first 100 you can first "take" as many as you need and then count them...you can also

atom / swap! question

2012-07-30 Thread Vinay D.E
I am a newbie and was doing some exercises when I ran across something that I don't understand. I am trying to count the number of elements in an array less than 100. My first attempt didn't work. The counter returns 0 (let [a (atom 0) i (take-while (fn[x] (swap! a inc) (< x 100)) [1 2 3

Re: atom/swap! question

2009-03-22 Thread Mark Volkmann
Thanks for looking this over! It's interesting how often I find myself trying to use an Atom because I'm not coordinating changes multiple things, just one, but the solution still requires using a Ref. I guess it's wrong to think of what I'm doing as coordinating one value. I'm really coordinating

Re: atom/swap! question

2009-03-22 Thread Meikel Brandmeyer
Hi, Am 21.03.2009 um 23:26 schrieb Mark Volkmann: I'm looking for a suggestion on how I can get new-struct. The other aspects aside, here an answer for this question. (defn get-new-struct [the-new-map] (the-new-map (last (keys the-new-map Or, to be sure, (defn get-new-struct [the

Re: atom/swap! question

2009-03-21 Thread Mark Volkmann
On Sat, Mar 21, 2009 at 6:12 PM, Laurent PETIT wrote: > Hello Mark, > > 2 questions / suggestions : > >  * couldn't step 2) be computed outside function b, and then my-data be > replaced by new-struct ? This way, if you have several flavors of function > b, you will not have to repeat the code in

Re: atom/swap! question

2009-03-21 Thread Laurent PETIT
Hello Mark, 2 questions / suggestions : * couldn't step 2) be computed outside function b, and then my-data be replaced by new-struct ? This way, if you have several flavors of function b, you will not have to repeat the code in steps 1) and 3) in each of those flavors of b ? And then the proble

atom/swap! question

2009-03-21 Thread Mark Volkmann
I'm using an atom to hold a sorted-map whose keys are integer ids and values are a particular kind of struct. I have a function, call it "a", that adds an entry to this map. It contains just this line: (swap! my-atom b my-data) "b" is a function that: 1) determines the next available id by getti