[R6RS] libraries

William D Clinger will at ccs.neu.edu
Thu Aug 17 18:40:32 EDT 2006

In this morning's conference call, I think I overstated
the performance hit caused by the multi-phase semantics
of libraries.  I will try to correct that here, but first
I want to explain why I am still opposed to multi-phase

For me, one of the guiding principles of language design
is that programs should pay only for the features they
use.  In terms of performance, I think I see how I can
come closer to that ideal than I had realized.  On the
other hand, I think the multi-phase semantics adds more
conceptual complexity to Scheme than it eliminates.  The
problem it solves is a corner case on a corner case, and
it doesn't even address what I believe will be the more
common ordering dependencies.

In my opinion, the most common ordering dependencies will
involve side effects to global state at phase 0.  For a
silly but easy-to-understand example, consider a library
whose initialization forms write a file to "/tmp", and
another library whose initialization forms read that file.
For a less silly example, consider a global registry of
some sort, where the order in which libraries register
themselves turns out to matter.

Programming discipline is the only solution I can imagine
for ordering dependencies such as the above.  It seems to
me that exactly the same kind of programming discipline
would solve the problems that motivate the multi-phase
semantics, and those problems can't even arise except in
programs that use procedural macros with stateful help
procedures that are defined in other libraries.  I expect
such programs to be very rare---and frankly, I think it
is poor style to write such programs anyway.

But I do think I see how to implement the multi-phase
semantics without any performance hit for programs that
I would consider to be well-constructed.  The idea is
simple:  If a script or library imports *any* library
for expand (which means it probably uses or contains
the procedural macros that are causing this performance
problem), then that script or library won't be compiled
at all; it will run as interpreted code.

Unless I'm missing something, this simple expedient
should allow me to compile all programs that don't use
procedural macros with help procedures that are imported
from another library.  In other words, I should be able
to compile all well-constructed programs, and I should
be able to use my existing optimization technology with
few modifications.


More information about the R6RS mailing list