On Fri, Mar 5, 2010 at 7:31 AM, Glen Rubin <rubing...@gmail.com> wrote:
> The problem was that coll was being called as a fcn as others pointed > out. You say the function being supplied as my second parameter does > not modify my third parameter? > > (defn pyt [coll] > (loop [b (rest coll)] > (map #(* % %) b))) > > I am taking the third parameter and squaring it. Isn't that a > modification? > > thx everybody for the help! > > On Mar 5, 7:15 am, Richard Lyman <richard.ly...@gmail.com> wrote: > > On Fri, Mar 5, 2010 at 7:05 AM, Glen Rubin <rubing...@gmail.com> wrote: > > > The following code does not work, when using (range 1 5) as coll > > > input: > > > > > (defn pyt [coll] > > > (loop [b (rest (coll))] > > > > > (map #(* % %) b))) > > > > > The real code was more complicated, but I refined it to its simplest > > > form while still producing the error. (map f coll) looks correct to > > > me?? :( > > > > I'm not sure what effect you're looking for, but... > > > > Don't forget, map is lazy and the function you've supplied as the second > > parameter doesn't modify b. > > > > Depending on what outcome you're looking for, you might want to wrap the > > call to map in a call to doall, or modify b and your second parameter so > > that b is changed. > > > > -Rich > Sorry for the miscommunication. Clojure 1.0.0- user=> (def b '(1 2 3)) #'user/b user=> b (1 2 3) user=> (map #(* % %) b) (1 4 9) user=> b (1 2 3) user=> I didn't know if "the real code" used b inside the let after the call to map and had expected it to be different. -Rich -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en