[plt-scheme] require and provide for arbitrary phase levels (3.99.0.13)

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Wed Feb 20 09:52:27 EST 2008

I've finally generalized `require' and `provide' to work for arbitrary
phase levels. Aside from better support for an R6RS-compatible
language, I think the practical consequences of this generalization are
few.

Using a phase level 2 import, it's now possible to write `let-syntax'
in the right-hand side of a `let-syntax' binding:

  (require (for-syntax scheme/base
                       (for-syntax scheme/base)))

  (let-syntax ([a (lambda (stx)
                    (let-syntax ([b (lambda (stx)
                                      #'5)])
                      #`#,(b)))])
    (a))

Actually, since `scheme/base' exports `syntax-rule' for syntax, and
since `for-syntax' in `require' now shifts all exported phase levels
(instead of truncating after phase level 0), a single `for-syntax' is
enough to use nested `let-syntax' with `syntax-rules':

  (require (for-syntax scheme/base))

  (let-syntax ([a (lambda (stx)
                    (let-syntax ([b (syntax-rules ()
                                      [(_) 5])])
                      #`#,(b)))])
    (a))

You can even import `scheme/base' into phase level 17 or -93, if you want:

  (require (for-meta 17 scheme/base)
           (for-meta -93 scheme/base))

Of course, that's as unlikely to be useful as a function that takes a
function that takes a function... 93 layers deep --- but generality
makes a cleaner language (and a slightly cleaner implementation).

Definitions are still limited to phase levels 0 and 1, and I have no
near-term plans to generalize that part.

Matthew



Posted on the users mailing list.