How Are Lazy Sequences Implemented in Clojure?

Viewed 3930

I like Clojure. One thing that bothers me about the language is that I don't know how lazy sequences are implemented, or how they work.

I know that lazy sequences only evaluate the items in the sequence that are asked for. How does it do this?

  • What makes lazy sequences so efficient that they don't consume much stack?
  • How come you can wrap recursive calls in a lazy sequence and no longer get a stack over flow for large computations?
  • What resources do lazy sequences consume to do what it does?
  • In what scenarios are lazy sequences inefficient?
  • In what scenarios are lazy sequences most efficient?
3 Answers
Related