Skip to content

Instantly share code, notes, and snippets.

@aboekhoff
Created May 13, 2010 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aboekhoff/399685 to your computer and use it in GitHub Desktop.
Save aboekhoff/399685 to your computer and use it in GitHub Desktop.
;; using a pattern matching macro
(defn test [x]
(match x
(? (comp not number?)) :not-a-number
(? #(< % 42)) (recur (inc x))
42 :booya!
_ :too-high!))
;; running mexpand-all on the match clause produces this mess:
(let*
[t__3449__auto__
(if ((comp not number?) x) :not-a-number :somnium.yap/match-failure)]
(if
(clojure.core/not
(clojure.core/= t__3449__auto__ :somnium.yap/match-failure))
t__3449__auto__
(let*
[t__3449__auto__
(if
((fn* ([p1__5784#] (< p1__5784# 42))) x)
(recur (inc x))
:somnium.yap/match-failure)]
(if
(clojure.core/not
(clojure.core/= t__3449__auto__ :somnium.yap/match-failure))
t__3449__auto__
(let*
[t__3449__auto__
(if (clojure.core/= x 42) :booya! :somnium.yap/match-failure)]
(if
(clojure.core/not
(clojure.core/= t__3449__auto__ :somnium.yap/match-failure))
t__3449__auto__
(let*
[t__3449__auto__ :too-high!]
(if
(clojure.core/not
(clojure.core/= t__3449__auto__ :somnium.yap/match-failure))
t__3449__auto__
(somnium.yap/raise!
"no matching clause for: "
(clojure.core/pr-str x)
" among patterns:\n"
'(? (comp not number?))
"\n"
'(? (fn* [p1__5784#] (< p1__5784# 42)))
"\n"
'42
"\n"
'_)))))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment