Not Variable Assignment, but Close

Once you get beyond the add a few numbers together stage you naturally start looking for a way to hang a name on the result. The most straightforward way to do that in Clojure is with def:

 (​def​ first-name ​"Russ"​)

There are very few surprises in using def. You give it an identifier—Clojure calls this a symbol—and a value, and def will associate, or bind, the symbol to the value. In this example the symbol is first-name and the value is the string "Russ". The value that you supply to def gets evaluated, so it can be any expression. So evaluating this

 (​def​ the-average (/ (+ 20 40.0) 2.0))

Will bind 30.0 to the-average.

One thing that you might find surprising is that it’s the-average and not theAverage ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.