[R6RS] Modules, a second question

William D Clinger will
Tue Sep 28 09:45:16 EDT 2004


(module foo r6rs
  (display (foo 3))
  (define (foo x) x))

Because the first definition of this module must signal an error,
Manuel writes:

> If it does I don't see how the compiler will be able to do a good job
> when compiling function calls...

First, let me say that I don't think it's terribly important for
a compiler to optimize top-level expressions, which are the only
ones that are made more difficult to optimize by the left-to-right
order of evaluation here.

Secondly, a compiler can optimize top-level expressions by doing
a little more work.  The example above doesn't export anything,
so it presumably macro-expands into something like

    (let ((foo '*))
      (display (foo 3))
      (set! foo (lambda (x) x)))

Several compilers, including my own Twobit compiler, expand down
to that level but still generate good code for calls to known
procedures.  See my notes on single assignment analysis at
http://www.ccs.neu.edu/home/will/Twobit/p2saa.html

> The bad consequence is that it will be hard for a compiler to deliver
> applications that won't be linked against the whole r6rs runtime
> system.  It is likely to be very hard to produce small Scheme
> executables...

I don't understand this argument.  To produce a small executable,
you link in only the things that might be referenced (directly or
indirectly) by the program.  That involves a static analysis of
the program.  With the module system, the program is divided into
modules, so the static analysis must be applied to modules.  So
what?  It's the same problem.

Will


More information about the R6RS mailing list