[R6RS] library syntax

dyb at cs.indiana.edu dyb at cs.indiana.edu
Mon Jul 24 11:12:12 EDT 2006

Here's a revision of the library syntax proposal.  Only the <export-spec>
syntax and associated note about phasihg is new.


 (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> --> (for (<export-set>*) <import-phase>*) | <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>.

  Phasing: The effective phases of an imported identifier are the ones
    specified in import for wrapper in the importing library, if any,
    otherwise the ones specified in the export for wrapper in the
    exporting module, if any, otherwise run.

  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

More information about the R6RS mailing list