Skip to content

Instantly share code, notes, and snippets.

@llasram
Created October 14, 2011 14:15
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 llasram/1287230 to your computer and use it in GitHub Desktop.
Save llasram/1287230 to your computer and use it in GitHub Desktop.
Version of `case' allowing compile-time evaluated expressions
(defmacro case-expr
"Like case, but only supports individual test expressions, which are
evaluated at macro-expansion time."
[e & clauses]
`(case ~e
~@(concat
(mapcat (fn [[test result]]
[(eval `(let [test# ~test] test#)) result])
(partition 2 clauses))
(when (odd? (count clauses))
(list (last clauses))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment