[R6RS] library syntax

dyb at cs.indiana.edu dyb at cs.indiana.edu
Tue Jul 4 12:28:12 EDT 2006


Matthew and I have settled on Variant I in my Jun 13 note outlining
library syntax options.  With this variant, the distinguished library
specifier goes away, a single import form (possibly with multiple
import-specs) is required, and a single export form is required.
We have also settled on plain identifiers for library names, possibly
using SRFI 84 as a quideline for creating unique library names.

  (library <lib-name>
    (import <import-spec>*)
    (export <export-spec>*)
    <library body>)

  <lib-name> --> <identifier>

  <library body> --> <command or definition>*

  <command or definition> --> <command>
      | <definition>
      | (begin <command or definition>*)
      | <derived command or definition>

  <definition> --> <variable definition>
      | <syntax definition>
      | (indirect-export <indirect-spec>*)

  <variable definition> --> (define <variable> <expression>)
      | (define (<variable> <def formals>) <body>)

  <syntax definition> --> (define-syntax <keyword> <transformer spec>)

  <lambda expression> --> (lambda <formals> <body>)

  <body> --> <command or definition>* <expression>

  <import-spec> --> <import-set> | (for <import-set> <import-phase>*)

  <import-phase> --> run | expand  ; possibley eval as well

  <export-spec> --> <export-set>

  <indirect-spec> --> (<identifier> <identifier>*)

  <import-set> --> <lib-name>
      | (only <X-set> <identifier>*)
      | (except <X-set> <identifier>*)
      | (add-prefix <X-set> <identifier>)
      | (rename <X-set> (<identifier> <identifier>)*)

  <export-set> --> <identifier>
      | (rename (<identifier> <identifier>)*)

  Scoping: all imports and definitions occupy a single scope within
    the library <body>.

  Rationale: This variant eliminates <language>, thereby allowing
    us to use the subsetting and renaming features of <import-spec>
    for all imported libraries.

    It also allows indirect-export in any definition context, so that
    macros that expand into macro definitions can also produce any
    necessary indirect-export forms.  indirect-export forms would be
    ignored except within a library <body>.

    It also allows lambda bodies to contain interleaved commands and
    definitions.  I didn't allow this in the syntax srfi because I thought
    that the library srfi required all of the definitions to appear before
    all of the commands/expressions.

    By requiring that the import and export forms be present, we turn
    these names into pure syntactic sugar and eliminate possible confusion
    about what happens if the names are defined by one of the imported
    libraries.

  Example:

    (library sane-if
      (import (rename r6rs (r6rs:if if)))
      (export if)
      (define-syntax if
        (syntax-rules ()
          [(_ e1 e2 e3) (r6rs:if e1 e2 e3)])))

    (library main
      (import (except r6rs if) sane-if)
      (export)
      (if #t (write 'hi) (write 'bye)))

I will be sending a separate note about libraries and transformer phases.

Kent



More information about the R6RS mailing list