A thought that struck me in the swimming pool today.

Lazy lists are another kind of late-binding.

Everyone hypes lazy lists by saying “wow! you can even have infinitely long lists!”

To which the natural response is, “So what? The universe is finite and my life and this program are certainly finite, why should I care?”

But, instead think about this. “Infinite lists” are really “unbounded lists” are really “when you create them, you don’t know how long you want them to be” lists.

It’s another part of the program, the “consumer” of the list, which knows how long you want them to be.

For example, I’m currently generating patterns in Clojure + Quil. Here’s one which is basically formed by filling a grid with a number of tiles.


The important thing here is that, although I know I want a repeated pattern of different tiles, I don’t need to know how many of these tiles in total I’m actually going to need to fill my grid, so I just create an infinite list, using

(cycle [tile1 tile2 tile3 tile4])

Then I have a function which zips the list of tiles with a list of positions to be filled. The list of tiles is infinite, but the list of positions on the grid isn’t, so the zipping ends up with a finite grid of tiles.

In a sense, this is yet another example of “late-binding” (ie. leaving decisions as late as possible). It allows the names of data-structures to stand for things (data-structure) whose shape and extent is determined much later.