[r6rs-discuss] Interpreters need not apply?

AndrevanTonder andre at het.brown.edu
Wed Mar 7 09:51:04 EST 2007


On Wed, 7 Mar 2007, Pascal Costanza wrote:

> The terms "compiler" and "interpreter" are not well-defined. But AFAICT, a 
> compiler typically works in two phases: A translation from one representation 
> to another one, where the latter is typically a representation that can be 
> executed by some interpreter (for example, a CPU).

No r5rs-conformant Scheme interpreter will start evaluating a form 
without macro-expanding it first.  R6RS requires nothing more than this.

> An interpreter typically works in one phase: It evaluates expressions one by 
> one without doing any sort of whole-program analysis.

But any serious existing Scheme interpreters will expand and syntax-check 
each form before evaluating it.  In particular, an r5rs lambda body has to 
be expanded as a whole before it can be evaluated - no one would dream of 
expanding and evaluating r5rs internal definitions one by one.  R6RS mandates 
nothing more than this.  An R6RS library is a single form containing a 
sequence of internal definitions (in a glorified letrec* subexpression) that 
can be read, expanded/analysed and evaluated once, just as one would do every 
toplevel form in an r5rs interpreter.  The same applies to an R6RS "toplevel 
program", which is also a glorified letrec* expression.  In my implementation, 
it can be entered at the prompt as a single form, e.g.,

  > (program
      (import (r6rs))
      (display "Hello world"))

  Hello world

R6RS does not preclude a traditional toplevel in which one can evaluate naked 
expressions.  My implementation in fact provides a traditional toplevel for 
interactive REPL development, at which one can type

  > (import (r6rs))

  unspecified

  > (display "Hello world")

  Hello world
  unspecified

> Interpreters are interesting because they sometimes have better performance 
> characteristics than compilers. Especially when code is loaded or generated 
> on demand at runtime, a compilation step may incur a much larger overhead 
> than "pure" interpretation. For example, this is the case when the loaded or 
> generated code is only executed once or just a few times.
>
> This is, BTW, one of the reasons why "modern" virtual machines, like those 
> for Java, Smalltalk or Self, are so efficient: They simply defer compilation 
> until there is enough evidence that certain hotspots actually benefit from an 
> extra compilation step.

Do you consider these language specifications more interpreter-friendly than 
r6rs?  If I remember correctly, all Java code has to be encapsulated in 
classes.  These have to be assembled into a well-formed program, which is 
sytax-checked and typed-checked, before anything will run.  Does r6rs mandate, 
in your view, a heavier burden than this?

Regards
Andre



More information about the r6rs-discuss mailing list