May 2018
Beginner to intermediate
290 pages
6h 43m
English
Let’s imagine we’ve come up with a simple rating system for books: you love a book, you hate it, or you’re completely indifferent to it. To handle this, we decide to represent book ratings with integers: positive numbers for good ratings, negative numbers for bad ratings, and zero for a devastating meh.
Given this design, we might end up writing code that looks like this:
| | (defn print-rating [rating] |
| | (cond |
| | (pos? rating) (println "Good book!") |
| | (zero? rating) (println "Totally indifferent.") |
| | :else (println "Run away!"))) |
Other than our use of pos? and zero? to pick out the numeric ranges, there is nothing very exciting going on here.
Now, if all we’re talking about ...
Read now
Unlock full access