Subject: Re: LISP for embedded systems
From: (Rob Warnock)
Date: 1999/10/27
Newsgroups: comp.lang.lisp
Message-ID: <7v5tgv$>
Bob Bane  <> wrote:
| Rob Warnock wrote:
| > But SIOD... doesn't even memoize macro expansions!
| > They're re-expanded every time the enclosing forms are executed.
| SIOD actually does memoize macro expansions, at least as of version 3.0:
| > (defmac (breedle form) `(cons ,(cadr form) ,(caddr form)))
| breedle-macro
| > breedle-macro
| #<CLOSURE (form) (replace form (list (quote cons) (cadr form) (caddr form)))>

Aha! Got me!! I had forgotten the "defmac" macro, which is defined in
the startup file "siod.scm":

	(define (replace before after)
	  (set-car! before (car after))
	  (set-cdr! before (cdr after))

	(define (defmac-macro form)
	  (let ((sname (car (cadr form)))
		(argl (cdr (cadr form)))
		(fname nil)
		(body (prognify (cddr form))))
	    (set! fname (symbolconc sname '-macro))
	    (list 'begin
		  (list 'define (cons fname argl)
			(list 'replace (car argl) body))
		  (list 'define sname (list 'quote fname)))))

	(define defmac 'defmac-macro)

In my test codes, I was using the "bare" underlying SIOD macro mechanism
[more polite than calling it a "hack"], that is, that if the value of the
function position of an application is a symbol, the symbol is taken to
name a macro expansion function [e.g., as shown above for how "defmac"
itself is defined]. This mechanism does not memoize expansions.

What I was missing is that macros defined using the "defmac" utility macro
are themselves defined to *rewrite* (with "replace") any forms that they're
applied to. [Since the form *must* be an "application" S-expr, to trigger
the macro mechanism, there's always a cons cell there to be overwritten.]

So we're both right, sort of: The underlying macro mechanism *doesn't*
memoize, but the way of defining macros provided in the standard startup
file *does*.

[I suspect I overlooked this because "defmac" appears *nowhere* in the
"siod.html" documentation! (*sigh*)]


Rob Warnock, 8L-846
Applied Networking
Silicon Graphics, Inc.		Phone: 650-933-1673
1600 Amphitheatre Pkwy.		FAX: 650-933-0511
Mountain View, CA  94043	PP-ASEL-IA