On Thu, Jan 1, 2009 at 10:14 PM, Andrew Baine <andrew.ba...@gmail.com> wrote:
> I want to get a seq of successive rests of the given seq:
> user> (defn f [seq]
> (if (empty? seq)
>  nil
>  (lazy-cons seq (f (rest seq)))))
> #'user/f
> user> (f '(1 2 3 4))
> ((1 2 3 4) (2 3 4) (3 4) (4))

That's very similar to "tails" in Haskell:
http://www.zvon.org/other/haskell/Outputlist/tails_f.html

> user> (take 10 (map #(take 5 %) (f (iterate inc 1))))
> ((1 2 3 4 5) (2 3 4 5 6) (3 4 5 6 7) (4 5 6 7 8) (5 6 7 8 9) (6 7 8 9 10) (7
> 8 9 10 11) (8 9 10 11 12) (9 10 11 12 13) (10 11 12 13 14))

For this particular example, you could use 'partition':
(take 10 (partition 5 1 (iterate inc 1)))

> Does this fn already exist in clojure?  If not what would an idiomatic name
> be for it from Haskell or CL?

I don't think it exists in clojure.core or clojure.contrib.

--Chouser

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