liveBook · Manning

Reader macro

As explained in Clojure: The Essential Reference

A reader macro is syntax that causes the Clojure reader to transform source text into another expression before evaluation.

A reader macro is syntax that makes the Clojure reader transform source text before evaluation. The #() form provides compact syntax for creating an anonymous function, serving as shorthand for fn. section 2.1.2

Anonymous function shorthand

((fn [x] (* (Math/random) x)) (System/currentTimeMillis)) and (#(* (Math/random) %) (System/currentTimeMillis)) create equivalent anonymous-function calls; the latter uses #() and %. section 2.1.2

How Clojure: The Essential Reference covers it

How deep it goes
Defines the shorthand and demonstrates equivalence with fn, but does not detail reader implementation internals.
Examples
Demonstrates #() beside fn in random-multiplier calls using the implicit argument symbol %.
What it assumes
Assumes familiarity with functions and function calls while contrasting the shorthand with explicit fn syntax.
What you can do after
Apply compact #() syntax to write anonymous functions in Clojure expressions.
How it connects
Connects reader macros with fn, anonymous functions, lambdas, and first-class functions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Clojure: The Essential Reference. The section links point to the parts of the book it draws on.