O'Reilly logo

Web Development with Clojure by Dmitri Sotnikov

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Being Lazy

Many Clojure algorithms use lazy evaluation. This means the operations aren’t performed unless somebody actually asks for their result. This is crucial to making many algorithms work efficiently.

For example, you might think the preceding example is very inefficient since we have to iterate our sequence each time to create the range, map across it, interpose, and reduce the result.

However, this is not actually the case. The evaluation of each expression happens on demand. The first value in range is generated and passed to the rest of the functions, then the next, and so on, until the sequence is exhausted. This is similar to the way iterators work in languages like Python.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required