Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Tassilo Horn
"Z.A" writes: > Meikel : To get the sequence printing logic i tried following code. Makes > no sense to me. > >(def lazy2 (take 3 (iterate #(do > (cond > (= 0 %) (print "+") > (= 1 %) (p

Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Z.A
Thanks everybody. Meikel : To get the sequence printing logic i tried following code. Makes no sense to me. (def lazy2 (take 3 (iterate #(do (cond (= 0 %) (print "+") (= 1 %) (print "*")

Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Pierre-Henry Perret
A form like: (def lazy2 (map #(str "+" %) (range))) would work. Le mercredi 6 juin 2012 11:24:06 UTC+2, Z.A a écrit : > > Hi > > user=> (def lazy1(take3 (iterate#(do (print "+") > (inc %))0))) > #'user/lazy1 > user=> lazy1 > (+0+1 2) > > Why am I not gettin

Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Meikel Brandmeyer (kotarak)
Hi, Am Mittwoch, 6. Juni 2012 12:13:56 UTC+2 schrieb Jim foo.bar: Your f is NOT free of side-effects...Nonetheless, I would expect (0 +1 > +2) instead of (+0 +1 2)! > Can anyone shine some light on this? > > When printing the sequence the tail is realized before the current item is printed

Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Pierre-Henry Perret
This is due to the fact that the evaluation of a do form returns the last expr... Le mercredi 6 juin 2012 12:23:07 UTC+2, Jim foo.bar a écrit : > > It's obvious that you're looking for: > > (def lazy1 (interleave (repeat '+) (range 3))) > > > but I still haven't figured out why you get: (+0 +

Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Jim - FooBar();
It's obvious that you're looking for: (def lazy1 (interleave (repeat '+) (range 3))) but I still haven't figured out why you get: (+0 +1 2) when using iterate! Jim On 06/06/12 11:13, Jim - FooBar(); wrote: From the docs: clojure.core/iterate ([f x]) Returns a lazy sequence of x, (f x

Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Jim - FooBar();
From the docs: clojure.core/iterate ([f x]) Returns a lazy sequence of x, (f x), (f (f x)) etc. f must be free of side-effects Your f is NOT free of side-effects...Nonetheless, I would expect (0 +1 +2) instead of (+0 +1 2)! Can anyone shine some light on this? Jim On 06/06/12 10:24, Z

Re: Last element of sequence returned by 'take' not showing side effects

2012-06-06 Thread Meikel Brandmeyer (kotarak)
Hi, because the first element is taken verbatim and the function is not applied to it. In this case it is the zero. (iterate f x) => (x (f x) (f (f x)) ...) So the pluses you see are for the 1 and the 2. Kind regards Meikel -- You received this message because you are subscribed to the Googl