Created
October 14, 2011 14:15
-
-
Save llasram/1287230 to your computer and use it in GitHub Desktop.
Version of `case' allowing compile-time evaluated expressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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