On May 5, 2:54 pm, Robert Luo <robort...@gmail.com> wrote: [snip] > (repeated-seq #(range % 5) 0) > > the elements are: 0 1 2 3 4 4 5 6 7 8 8 ...
I think you mean, (def s (repeated-seq #(range % (+ % 5)) 0) ) > However, I want to get rid of the duplicated index element (4, 8 etc), > e.g. > To produce 0 1 2 3 4 5 6 7 8 9 > > But when I insert a rest into lazy-seq, the function just hung up. > How can I make this happen? I don't know if this is what you meant, but: I think it depends on where you put the 'rest' Try: (defn repeated-seq [f start] (let [coll (f start)] (concat coll (lazy-seq (rest (repeated-seq f (last coll))))))) As opposed to (defn repeated-seq [f start] (let [coll (f start)] (concat coll (rest (lazy-seq (repeated-seq f (last coll))))))) it isn't particularly efficient, though.. /Karl -- 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