This three part series of blog posts is a tutorial on how Clojure tackles the problem of polymorphism by implementing the Number system from SICP in Clojure using its protocols and multiple dispatch features. The Number system has exactly the right level of complexity to require the use of all of Clojure's features for polymorphism.
In Part 1, I implement Complex Numbers with two different representations, and show how to abstract away the difference using Protocols. In the end we end up with a system that can add, divide, and multiply complex numbers regardless of their internal representation.
Nov 21, 2016