Created
December 3, 2011 08:09
-
-
Save m2ym/1426513 to your computer and use it in GitHub Desktop.
My Macrolet
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
(in-package :cl-user) | |
(defmacro my-macrolet (&environment env bindings &body body) | |
(let* ((local-macros | |
(loop for (name lambda-list . body) in bindings | |
for macro-lambda = (sb-cltl2:parse-macro name lambda-list body) | |
for macro-fun = (sb-cltl2:enclose macro-lambda env) | |
collect `(,name ,macro-fun))) | |
(new-env (sb-cltl2:augment-environment env :macro local-macros))) | |
(sb-cltl2:macroexpand-all `(locally ,@body) new-env))) | |
(my-macrolet ((twice (x) `(+ ,x ,x))) | |
(let ((x 0)) | |
(twice (incf x)))) | |
;=> 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment