Skip to content

Instantly share code, notes, and snippets.

@osa1
Created January 28, 2012 13:07
Show Gist options
  • Save osa1/1694247 to your computer and use it in GitHub Desktop.
Save osa1/1694247 to your computer and use it in GitHub Desktop.
case-eval
(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