Created
October 14, 2011 13:49
-
-
Save jcromartie/1287160 to your computer and use it in GitHub Desktop.
Clojure "case", compatible with Java static values
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
;; warning: this is probably dangerous and stupid | |
(defmacro staticase | |
[expr & cases] | |
(let [case-pairs (partition 2 cases) | |
evaled-pairs (map (fn [[l r]] [(if (symbol? l) (eval l) l) r]) case-pairs) | |
evaled-cases (flatten evaled-pairs)] | |
`(case ~expr ~@evaled-cases))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment