Skip to content

Instantly share code, notes, and snippets.

@kurohuku
Created January 24, 2011 02:37
Show Gist options
  • Save kurohuku/792730 to your computer and use it in GitHub Desktop.
Save kurohuku/792730 to your computer and use it in GitHub Desktop.
(defmacro case+ (form test &body clauses)
(let ((gtest (gensym))
(gform (gensym)))
(labels
((clause->or (clause)
(if (listp (car clause))
`((or
,@(mapcar
#'(lambda (x)
`(funcall ,gtest ,gform ,x))
(car clause)))
,@(cdr clause))
(cond
((eq (car clause) cl:T)
`(cl:T ,@(cdr clause)))
((and (symbolp (car clause))
(string-equal (symbol-name (car clause)) "otherwise"))
`(cl:T ,@(cdr clause)))
(T `((funcall ,gtest ,gform ,(car clause))
,@(cdr clause)))))))
`(let ((,gform ,form)
(,gtest ,test))
(cond
,@(mapcar #'clause->or clauses))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment