February 2018
Intermediate to advanced
304 pages
7h 11m
English
The best way to appreciate multimethods is to spend a few minutes living without them, so let’s do that. Clojure can already print anything with print/println. But pretend for a moment that these functions don’t exist and that you need to build a generic print mechanism. To get started, create a my-print function that can print a string to the standard output stream *out*:
| | (defn my-print [ob] |
| | (.write *out* ob)) |
Next, create a my-println that calls my-print and then adds a line feed:
| | (defn my-println [ob] |
| | (my-print ob) |
| | (.write *out* "\n")) |
The line feed makes my-println’s output easier to read when testing at the REPL. For the rest ...
Read now
Unlock full access