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

macro memoization warning

Someone should have corrected me on an earlier posting: EQ-based macro
expansion memoization doesn't work.

    (define-syntax mumble (syntax-rules ()
			    ((mumble var exp)
			     (list exp (let ((var 13)) exp)))))
    (define-syntax grumble (syntax-rules (a)
			     ((grumble a) 5)
			     ((grumble x) 8)))
    (let ((a 3))
      (mumble a (grumble a)))  ;should be (5 8), not (5 5)

Maclisp-style side-effecty memoization works even less well, of

    (define-syntax show
      (syntax-rules () ((show x) (list 'x = x))))

    (show (let ((y 3)) y))    ;assuming LET is a macro

These problems would be mitigated if macro transformers ensured that
their output was a tree, not a DAG - i.e. no shared substructure.
That is, the two x's in SHOW's output should be copied so as to be
fully non-EQ to each other.