-
Notifications
You must be signed in to change notification settings - Fork 64
Features
core.match adds sophisticated pattern matching support to the Clojure programming language. Currently two implementations are fully supported - Clojure on the JVM, and ClojureScript. Because core.match is implemented purely via macros it should be trivial to get up and running on other Clojure implementations.
Unlike pattern matching found in most functional programming languages
core.match does not promote matching on concrete types. Instead
core.match matches on much more abstract interfaces -
IPersistentVector
, ILookup
, Sequential
and so on.
For example here is a simple pattern match:
(let [x true
y true
z true]
(match [x y z]
[_ false true ] 1
[false true _ ] 2
[_ _ false] 3
[_ _ true ] 4
:else 5))
We've formatted it to make the clauses a bit more clear. Obviously
this expression will return 4
.
See Basic Usage for more examples and Advanced Usaged for directions on how to extend your custom data types so they can participate in pattern matching.