May 2018
Beginner to intermediate
290 pages
6h 43m
English
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 ...
Read now
Unlock full access