Skip to content

Instantly share code, notes, and snippets.

@apskii
Created February 10, 2012 06:00
Show Gist options
  • Save apskii/1787071 to your computer and use it in GitHub Desktop.
Save apskii/1787071 to your computer and use it in GitHub Desktop.
cl-hacking with macroexpand-hook
(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