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

Re: issue DEFINING-MACROS-NON-TOP-LEVEL, version 6



Suppose I have the example from CLtL:

(let ((old-count *access-count*))
    (unwind-protect
        (progn 
	    (incf *access-count*)
	    (perform-access))
	(setq *access-count* old-count)))

This is entirely equivalent to:

(let ((old-count *access-count*))
    (let ((thunk  #'(lambda () (setq *access-count* old-count))))
        (unwind-protect
	    (progn
	        (incf *access-count*)
		(perform-access))
	    (funcall thunk))))

This is a real example from the A-Lisp compiler.  A-Lisp implements
UNWIND-PROTECT by pushing a "thunk" (a function of no arguments) which
performs the cleanup actions onto the catch stack, before executing
the protected form.  Since the compiler has to generate code to fiddle
with the "thunk" before it emits the code for the protected form, it
seems perfectly reasonable for it to rearrange the source code.  A-Lisp
does in fact use a source-to-source transformation in the first phase of
the compiler to do this.

-Sandra
-------