Google
 

Trailing-Edge - PDP-10 Archives - clisp - clisp/upsala/macromemo.clisp
There are no other files named macromemo.clisp in the archive.
;;; -*- Lisp -*-
;;;
;;; **********************************************************************
;;; This code was written as part of the Spice Lisp project at
;;; Carnegie-Mellon University, and has been placed in the public domain.
;;; If you want to use this code or any part of Spice Lisp, please contact
;;; Scott Fahlman (FAHLMAN@CMUC). 
;;; **********************************************************************
;;;
;;; Macro memoization for Spice Lisp.
;;; Written by Skef Wholey.
;;; Modified by JoSH.
;;;
;;; If *Macroexpand-Hook* is set to Memoize-Macro-Call, macro calls will
;;; be memoized.
;;;

(in-package 'lisp)

(export '(memoize-macro-call))

(defun memoize-macro-call (expander expression)
  "Replaces the call to a macro in Expression with a call to the expanded form
  with magic stuff wrapped around it."
  (let ((expansion (funcall expander expression)))
    (if (eq (car expression) '*macroexpansion*) nil  ; "unless" is a macro...
	(displace expression (list '*macroexpansion* expansion
				   (cons (car expression) (cdr expression)))))
    expansion))

(defun displace (x y)
  "Replaces the CAR and CDR of X with the CAR and CDR of Y, returning the
  modified X."
  (rplaca x (car y))
  (rplacd x (cdr y)))

(defmacro *macroexpansion* (expansion original)
  (declare (ignore original))
  expansion)

(setq *macroexpand-hook* 'memoize-macro-call)