Created
February 10, 2012 06:00
-
-
Save apskii/1787071 to your computer and use it in GitHub Desktop.
cl-hacking with macroexpand-hook
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
| (defvar *source-storage* (make-hash-table)) | |
| (defun source-of (name) | |
| (gethash name *source-storage*)) | |
| (defun source-save-hook (expander form env) | |
| (when (eq (car form) 'defun) | |
| (setf (gethash (cadr form) *source-storage*) | |
| form)) | |
| (funcall expander form env)) | |
| ;; switch between standard hook and custom | |
| (let ((hook 'source-save-hook)) | |
| (defun source-save-mode () | |
| (rotatef *macroexpand-hook* hook))) | |
| ;; enter source-saving-mode | |
| (source-save-mode) | |
| (defun test (x y) | |
| (* x y x y)) | |
| ;; test it: | |
| (source-of 'test) | |
| ; => (DEFUN TEST (X Y) (* X Y X Y)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment