Record Confusion

If you’re coming to Clojure from an object-oriented language, then this record and protocol talk probably rings a very familiar bell. Record types and their instances do look a lot like the classes and objects that you find in object-oriented languages. And protocols clearly resemble the abstract types or interfaces that you also find in the object-oriented world. None of this is by chance. Records are Clojure’s approach to building a structured, composite data type with predefined fields. Similarly, protocols are Clojure’s riff on type-based polymorphism—the idea that you can have a single operation implemented in different ways by different types.

But record types and values part company with object-oriented classes and objects ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.