Hi, Tassilo. On Thursday, July 12, 2012 9:22:11 AM UTC+3, Tassilo Horn wrote: > > And there is no sense in having a lazy-seq in a loop-recur, because the > latter is inherently eager. Your accumulator will be a fully realized > lazy-seq. That is, the loop-recur defeats the purpose of lazy-seq, > i.e., defer the calculation of values until they are needed. > > Although you say the example is only for illustration, it could be > written much more concise (and lazy) like so: > > --8<---------------cut here---------------start------------->8--- > user> (defn list-set [s n v] > (concat (take n s) [v] (drop (inc n) s))) > #'user/list-set > user> (list-set [0 1 2 3] 2 :foo) > (0 1 :foo 3) > user> (list-set (list 0 1 2 3) 2 :foo) > (0 1 :foo 3) > --8<---------------cut here---------------end--------------->8--- > > Bye, > Tassilo > Oh, I see. I didn't realize the loop-recur eagerness - that's my fault. I'm pretty good in functional programming, though new to Clojure, so I knew how to accomplish the similar task using concat/take/drop/etc apparatus, but thanks anyway.
-- 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