Clojure: What is the underlying data structure of a lazy sequence?

130 Views Asked by At

As stated above, what is the underlying data structure of a lazy sequence ? Is it a list ? If it is, then what kind of list is it ? Where can I find references about this ?

1

There are 1 best solutions below

0
On BEST ANSWER

The data structure is a clojure.lang.Lazyseq, defined here. The lazy-seq macro creates such.

As you can see, a LazySeq is essentially a linked list which starts life with a thunk (zero-parameter function) member fn. When the sequence is realized, fn is used to generate data member s or sv and is itself annulled. I can't quite figure out how s and sv relate to one another.