May 2018
Beginner to intermediate
290 pages
6h 43m
English
Another thing that usually comes early in learning a programming language is figuring out how to do basic arithmetic. Clojure’s approach to doing math is refreshingly—and perhaps a little disconcertingly—simple. To see what this means, let’s add a couple of numbers together:
| | (+ 1900 84) |
Run the expression in that example through the REPL and you will get back 1984. You do multiplication, subtraction, and division in the same way:
| | (* 16 124) ; Gives you 1984. |
| | (- 2000 16) ; 1984 again. |
| | (/ 25792 13) ; 1984 yet again! |
As you might expect, you can assemble these basic math operations into arbitrarily complex expressions. Thus you can get the average of 1984 and 2010 with this:
| | (/ (+ 1984 2010) 2) |
Arithmetic in Clojure can be ...
Read now
Unlock full access