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

Anonymous Functions

Clojure allows creation of functions without having to name them. Such functions are referred to as lambda expressions. These functions can be defined by using the fn special form. A special form is a type of a primitive that is evaluated using different rules than the standard primitives. Each special form can have a unique way to evaluate its arguments.

For example, if we wanted a function that prints a single argument, we could write the following:

 
(​fn​ [arg] (​println​ arg))

We could then pass a parameter to this function to be printed.

 
((​fn​ [arg] (​println​ arg)) ​"hello"​)
 
 
=>​"hello"

Clojure also provides syntactic sugar for defining anonymous functions using the # notation. The preceding function can ...

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