Protocols

The word protocol is one of those nontechnical terms—it originally meant the set of rules for coping with a visit from the ambassador from Naboo and similar situations—that has picked up a variety of technical meanings, mostly around networking and communications. The meaning of protocol in Clojure is closer to the diplomatic original. A Clojure protocol is a set of how to behave rules expressed in code.

To see how protocols work, let’s imagine that along with the FictionalCharacter. we had a second record type, one used to track employees at a company:

 (defrecord Employee [first-name last-name department])

Nothing is really new here: Employee is just a record type with three fields. Armed with this new definition, we can cook up ...

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.