Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created October 14, 2011 13:49
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 jcromartie/1287160 to your computer and use it in GitHub Desktop.
Save jcromartie/1287160 to your computer and use it in GitHub Desktop.
Clojure "case", compatible with Java static values
;; 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