© Mark McDonnell 2017

Mark McDonnell, Quick Clojure, https://doi.org/10.1007/978-1-4842-2952-1_7

7. Pattern Matching

Mark McDonnell

(1)southend-on-Sea, UK

Pattern matching is the ability to trigger specific functionality based upon predefined patterns. These predefined patterns are applied to an incoming message (or user input).

There are somewhat related variations of this technique, which are referred to as runtime polymorphism and dynamic dispatch. In essence, these concepts refer to the selecting of an implementation based upon the known receiver at runtime. Pattern matching is similar, but from a practical standpoint is narrower in scope.

Clojure has a few different mechanisms for achieving this form of runtime dispatching of functionality. ...

Get Quick Clojure: Effective Functional Programming 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.