clojure/core.match — pull request #5 by takeoutweight (2014-05-04 23:29:19+00:00)
Title: macroexpand patterns before emitting

This seems like it could be a handy way to create custom binding forms for matching.

eg:
```clojure
(defrecord RegularClue [round category-idx question-idx])
(defrecord FinalClue [round])

(defmacro single-jeopardy [c-idx q-idx]
{:round :single-jeopardy
:category-idx c-idx
:question-idx q-idx})
(defmacro double-jeopardy [c-idx q-idx]
{:round :double-jeopardy
:category-idx c-idx
:question-idx q-idx})
(defmacro final-jeopardy []
{:round :final-jeopardy})

;eg:
(match [(regular-clue)]
[(single-jeopardy x y)] [:sing x y]
[(double-jeopardy cat q)] [:dub cat q]
[(final-jeopardy)] :final-jeopardy)

; or a :keys like destructuring
(defmacro rec-keys [klass & keys]
(list (into {} (map (fn [k] [(keyword k) k]) keys))
:guard `#(instance? ~klass %)))

(match [(regular-clue)]
[(rec-keys RegularClue category-idx)] category-idx
[(rec-keys FinalClue)] :final-jeopardy)
```