February 2018
Intermediate to advanced
304 pages
7h 11m
English
Multimethods let you create ad hoc taxonomies, which can be helpful when you discover type relationships that are not explicitly declared as such.
For example, consider a financial application that deals with checking and savings accounts. Define a Clojure map for an account, using a tag to distinguish the two:
| | (ns examples.multimethods.account) |
Now, you’re going to create two different checking accounts, tagged as ::checking and ::savings. The doubled :: causes the keywords to resolve in the current namespace. To see the namespace resolution happen, compare entering :checking and ::checking at the REPL:
| | :checking |
| | -> :checking |
| | |
| | ::checking |
| | -> :user/checking |
Placing keywords ...