Created
October 30, 2009 17:38
-
-
Save drewr/222567 to your computer and use it in GitHub Desktop.
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
(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