[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Portable macroexpansions again



Here is another portable macroexpander, one that has been working well for
me on both the Lucid and Franz products.  Perhaps it can be of use
to portability of the PCL code walker or others.  Please respond with comments,
rotten fruit, etc.:

In alternate-macroexpand-1, "env" is the code walker's own variety of
environment data structure.  Macro-env-spec is something this code
calls that returns a list of local macro definitions in the same form
as in a macrolet.  I compute and retain this every time the local
macroexpansion environment changes due to flet or macrolet, stacking
and unstacking it along with other environmental information.

;;; Call this like macroexpand-1, but only in cases where the
;;; form is determined to be a macro call.  Only the first returned value is
;;; useful.
(defun alternate-macroexpand-1 (form &optional env)
  (let ((spec (macro-env-spec env)))
    (if spec
	(eval `(macrolet ,spec
		 ()
		 (expansion ,form)))
      (macroexpand-1 form))))

;;; Expands into a form that evaluates to the macroexpansion of FORM in the
;;; current macro environment.
(defmacro expansion (form &environment env)
  (list 'quote
	(macroexpand-1 form env)))