Created
January 28, 2012 13:07
-
-
Save osa1/1694247 to your computer and use it in GitHub Desktop.
case-eval
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-eval (testform &body clauses) | |
"Like case, but the keys are evaluated. (They're still compared with EQL)." | |
(let ((value (gensym))) | |
`(let ((,value ,testform)) | |
(cond | |
,@(mapcar (lambda (clause) | |
(destructuring-bind (keys &body body) clause | |
(if (atom keys) | |
`((eql ,value ,keys) ,@body) | |
`((or ,@(mapcar (lambda (key) `(eql ,value ,key)) keys)) ,@body)))) | |
clauses))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment