PLI Lecture 12
Scheme meta-circular interpreters (cont.), and compilers

Scheme interpreters, continuations, compilation, lazy evaluation, polymorphic type checking

1. SCHEME

References:
* schemers.org
* Matthias Felleisen, Robert Bruce Findler, Matthew Flatt and 
  Shriram Krishnamurthi, How to Design Programs, MIT Press, 2001
* Daniel Friedman and Matthias Felleisen, The Little Schemer,
  Fourth edition, MIT Press 1995.
* Dorai Sitaram, Teach Yourself Scheme in Fixnum Days, 2004.
* Kent Dybvig, The Scheme Programming Language, Third Edition, 
  Prentice Hall, 2003.
* Revised^5 Report on the Algorithmic Language Scheme

Implementations:
* Guile, available on most GNU/Linux systems, including dwarf
* DrScheme, simpler, available on all common platforms
* Scm, available on every platform with a C compiler
* Chez Scheme, efficient, available on all common platforms
* Many others

Examples:
* Initial examples
* Simple let- and let*-expression examples
* Simple example to distinguish dynamic and static binding
* Continuation-passing style examples 
  A continuation is a unary function applied to the result 
  of evaluating an expression.  Note that writing programs
  in continuation-passing style, using data structures for
  continuations, results in imperative programs that operate
  on recursive data structures.
* Simple call-with-current-continuation examples
* More complex call-with-current-continuation examples

2. META-CIRCULAR AND EXPLICIT CONTROL SCHEME INTERPRETERS

* See Lecture 7 for background material.
* Scheme evaluator using static binding
* Explicit control evaluator using continuations
  See also environments.s.
* Explicit control evaluator using continuations 
  represented as data structures
  See also continuations2.s.
* Explicit control evaluator with call/cc

Note: The last two evaluators are tail-recursive, do not use higher-order 
functions, and can be directly implemented in any simple (nonrecursive)
language (provided it has dynamic storage allocation with GC).

Note: The last evaluator (trivially) allows a very powerful
control construct to be implemented in the same simple language.

References:
* Hal Abelson and Jerry Sussman, Structure and Interpretation 
  of Computer Programs, Second Edition, MIT Press, 1996.
* Daniel Friedman, Mitchell Wand and Christopher Haynes,
  Essentials of Programming Languages, First Edition (MIT Press, 1992),
  Second Edition (MIT Press, 2001).

3. SCHEME COMPILATION

References
* A. Ghuloum, An Incremental Approach to Compiler Construction
* M. Feeley, The 90 minute Scheme to C compiler.  (Apparently no longer 
available online.)

4. LAZY EVALUATION

Reference:
* Andrew Appel, Modern Compiler Implementation in Java, Second 
  Edition, CUP, 2002.  Chapter 15.

5. POLYMORPHIC TYPE ANALYSIS

Reference:
* Andrew Appel, Modern Compiler Implementation in Java, Second 
  Edition, CUP, 2002.  Chapter 16.