On Dec 13, 3:05 pm, Stephen Compall <stephen.comp...@gmail.com> wrote:
> On Mon, 2011-12-12 at 10:53 -0800, Michael Jaaka wrote:
> > (defn conr[ col item ]
> >    (lazy-seq
> >            (if (seq col)
> >                    (cons (first col) (conr (rest col) item))
> >                    (list item))))
>
> > And now stick with it.
> > All works as desired:
>
> > (conr (conr (conr '( 1 2 3) 4) 6) 7)
>
> Though you should note that, despite the `lazy-seq' wrapper around the
> body, as soon as you force the outermost seq, you're forcing all the way
> down.

Perhaps I don't understand what you're saying, but I disagree. For
example:


user> (first (conr (take 10 (map #(do (println "realizing" %) %)
(iterate inc 0))) 'x))
realizing 0
0

user> (last (conr (take 10 (map #(do (println "realizing" %) %)
(iterate inc 0))) 'x))
realizing 0
realizing 1
realizing 2
realizing 3
realizing 4
realizing 5
realizing 6
realizing 7
realizing 8
realizing 9
x

As you can see, only as many elements are realized as are needed to
satisfy the user's request.

-- 
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

Reply via email to