[r6rs-discuss] Question about "expand time" vs. "execution time"

From: Brian C. Barnes <bcbarnes>
Date: Sun, 27 May 2007 20:07:30 -0500

As you may have guessed by my recent flood of questions, I've pretty much
finished up my interpreter for 5.93 (except for syntax-case), and I'm now
going back and looking at all the things I left as "TODO" items. Among them
is the concept of "expansion time" vs. "execution time", and how that
relates to syntax-rules and libraries.

 

It seems that there is really no way to expand a macro until it is about to
be executed. Particularly in the face of being able to pass arbitrary
functions around. Consider, for example:

 

(import (rnrs))

 

(define-syntax ttf

    (syntax-rules ()

        ((_) #f)

        ((_ var) var)

        ((_ var1 var2) (+ var1 var2))))

 

(define bProc

    (lambda (n)

        (display (n))(newline)

        (display (n 5))(newline)

        (display (n 5 2))(newline)))

 

(bProc ttf)

 

 

In this case, when "bProc" is parsed, there is no indication what the
procedure "n" is going to be. It is not possible to expand the macro "ttf"
into bProc until it actually tries to execute. It is during execution that
the interpreter knows that "n" is an application of the macro ttf, and can
then expand it into place in the appropriate form. Also, it can't be
expanded by the application "(bProc ttf)", because we are simply passing it
as an argument, and don't know how (or even if) it is going to be applied.
Given this, I see no alternative but to wait until execution time, and then
expand the macro when it is being applied in the various "display" forms
shown above. This being true, what is the usefulness of "expand time" versus
"execution time" that is specified in the "for" clause of the library import
specification? If macros can't be expanded at "expand time" then what is
"expand time" meant for? If macros are to be expanded at "expand time" can
someone give me a hint how you would do this when you don't know, as in the
case above, that a macro is even being referenced, or in which form?

 

Brian C. Barnes

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.r6rs.org/pipermail/r6rs-discuss/attachments/20070527/935a6640/attachment.htm
Received on Sun May 27 2007 - 21:07:30 UTC

This archive was generated by hypermail 2.3.0 : Wed Oct 23 2024 - 09:15:01 UTC