O'Reilly logo

Clojure for Finance by Timothy Washington

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

First-class functions

The next functions that we'll look at are repeatedly and fn. The repeatedly function takes a second function and returns an infinite (or n length if supplied) lazy sequence of calls to this second function. This is the first encounter with a function that can take another function. We'll also encounter functions that return other functions. Described as first-class functions, these fall out of the lambda calculus and are the central features of functional programming.

As such, we need to wrap our previous (rand 35) call in another function. The fn function is one of Clojure's core functions and produces an anonymous, unnamed function. We can now supply this function to repeatedly.

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