Skip to content

Instantly share code, notes, and snippets.

@swannodette
Created August 3, 2011 04:10
Show Gist options
  • Save swannodette/1121891 to your computer and use it in GitHub Desktop.
Save swannodette/1121891 to your computer and use it in GitHub Desktop.
seqpat2.clj
(let [x 1 y 2 z 4]
(match [x y z]
[1 2 b] b
[a 2 4] a))
;; =>
(cond
(= x 1) (cond
(= y 2) (let [b z] b)
:else (throw (java.lang.Exception. "Found FailNode")))
:else (cond
(= y 2) (cond
(= z 4) (let [a x] a)
:else (throw
(java.lang.Exception. "Found FailNode")))
:else (throw (java.lang.Exception. "Found FailNode"))))
;; perf
;; 170ms
(let [x '(1 2 nil nil nil)]
(dotimes [_ 10]
(time
(dotimes [_ 1e6]
(match [x]
[(1)] :a0
[(1 2)] :a1
[(1 2 nil nil nil)] :a2)))))
;; 750ms
(let [x '(1 2 nil nil nil)]
(dotimes [_ 10]
(time
(dotimes [_ 1e6]
(let [[a b c d e] x])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment