Created
October 15, 2010 05:36
-
-
Save kurohuku/627686 to your computer and use it in GitHub Desktop.
labels
This file contains hidden or 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 dynamic-labels | |
((&rest definitions) &body body) | |
(let ((olds (mapcar #'(lambda (x) | |
(declare (ignore x)) | |
(gensym)) | |
definitions))) | |
`(let ,(mapcar | |
#'(lambda (sym def) | |
`(,sym ,(and (fboundp (car def)) (symbol-function (car def))))) | |
olds | |
definitions) | |
,@(mapcar | |
#'(lambda (def) | |
`(,(if (generic-function-p (car def)) | |
`cl:defmethod | |
`cl:defun) | |
,@def)) | |
definitions) | |
(unwind-protect | |
(progn | |
,@body) | |
,@(mapcar | |
#'(lambda (old def) | |
`(if ,old | |
(setf (symbol-function ',(car def)) | |
,old) | |
(fmakunbound ',(car def)))) | |
olds | |
definitions))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment