May 2018
Beginner to intermediate
290 pages
6h 43m
English
The wonderful thing about eval is that it’s simultaneously a gateway to the entire Clojure programming language and a very ordinary function. That eval is just an ordinary function raises an interesting question: can we—as an intellectual exercise—implement our own version of eval?
Remarkably, we can. We’ve already seen that if you hand eval a string or a keyword or a number, you get the same string, keyword, or number back, unchanged. So here’s a start on our own toy eval function:
| | (defn reval [expr] |
| | (cond |
| | (string? expr) expr |
| | (keyword? expr) expr |
| | (number? expr) expr |
| | :else :completely-confused)) |
Note that the real eval throws an exception when you hand it something it doesn’t understand, but to keep the example ...
Read now
Unlock full access