Skip to content

Instantly share code, notes, and snippets.

@drewr
Created October 30, 2009 17:38
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 drewr/222567 to your computer and use it in GitHub Desktop.
Save drewr/222567 to your computer and use it in GitHub Desktop.
(ns com.draines.test)
(defmacro casen [n switch]
(let [f (fn [m]
(let [s (format "x-%d" m)
k (keyword s)]
[k s]))
disps (map f (range 1 (inc n)))]
`(case ~switch
~@(apply concat disps))))
(time (casen 5 :x-5))
; "Elapsed time: 0.045 msecs"
(time (casen 50 :x-50))
; "Elapsed time: 0.019 msecs"
(time (casen 100 :x-100))
; "Elapsed time: 0.025 msecs"
(time (casen 500 :x-500))
; java.lang.IllegalArgumentException: No distinct mapping found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment