This is a proposal for modules in the R7RS small Scheme language, a
feature required by the current draft charter for WG1.  I am publishing
this document to invite wide comment.  There is nothing official about it.
I acknowledge the kind help of Alex Shinn in the discussions that led
up to this document.  However, I retain sole responsibility for it,
including all errors.

The syntax I am proposing is mostly a subset, with two extensions, of
the R6RS library syntax.  However, I'm using the keyword "module" rather
than "library".  This is a temporary feature pending the acceptance of
the extensions in large Scheme's module system; if they are accepted,
the two systems will be directly upward compatible and can share the
"library" keyword.

A small Scheme module takes the general form:

        (module module-name
          [(export name ...)]
          [(import importspec ...)]
          [(feature-groups name ...)]
          form ...)

This defines a module with the name module-name, which is either a simple
identifier or a list of simple identifiers.  The utility of hierarchical
namespaces has long been established, but I propose that small Scheme
allow simple identifiers for simple cases.

The export list specifies the names exported by this module.  Renaming
identifiers on export is not part of this proposal, though some form of
"deprefixing" would be a Good Thing.  I'm not sure just how to specify
it, though.

The import list specifies the modules imported by this module.
Import specs can be either module names, or else take the form (prefix
module-name name).  In the latter case, the exported identifiers of
the specified module are prefixed with prefix (an identifier) before
importing.

The feature-groups list specifies the feature groups which this
implementation must provide in order for the module to work.  This is
an extension to R6RS, which does not have feature groups.  If the
implementation cannot load the feature groups dynamically, it must
fail to define the module.  (Why aren't feature groups just modules?
Because they don't define separate namespaces, and because they mostly
reflect the limitations of particular small Scheme systems rather than
components that can be loaded into them.)

The forms constituting the body of the module are either Scheme
definitions, or Scheme expressions, or (include "filename") forms in any
order.  The semantics of the ordering are the same as that of a REPL;
in particular, any forward reference to an unknown name is presumed
to be to an unknown variable rather than to an unknown syntax; macros
cannot be used before they are defined.  Include forms cause the direct
incorporation of the contents of the form, and differ from load in two
ways: they refer only to source code files, and they happen at macro
expansion time rather than run time.  These rules deviate from those
of R6RS.

Allowing include forms means that it is possible, though not required,
to completely separate modules from the Scheme code that defines the
identifiers they declare.  Indeed, the same code can be included in
more than one module.  Include forms aren't in R6RS, but can be defined
using syntax-case or another low-level macro system; under my proposal,
small Scheme only has syntax-rules.

Importing a module causes any code in, or included in, the module to
be loaded if the implementation can figure out where to load it from.
In some cases this may not be possible, and the code will have to be
loaded separately.

In the top level (that is, outside any module), import and include
are both available and do what you'd expect at macro expansion time.
Unlike R6RS top-level programs, the small Scheme top level is not required
to have all imports at the beginning.

Module names, like feature groups, are recognized by cond-expand (from
SRFI 0), which makes it possible to conditionally control the actions
of a program depending on what modules have been imported into it.

Other than as specified here, the provisions of R6RS section 7.1 apply.
Since there are no macros except syntax-rules macros, implicit phasing
is sufficient.  What, if anything, to do about version numbers on modules
remains an open issue:  I don't believe they are necessary for small Scheme.

-- 
At the end of the Metatarsal Age, the dinosaurs     John Cowan
abruptly vanished. The theory that a single         [email protected]
catastrophic event may have been responsible        http://www.ccil.org/~cowan
has been strengthened by the recent discovery of
a worldwide layer of whipped cream marking the
Creosote-Tutelary boundary.             --Science Made Stupid

_______________________________________________
r6rs-discuss mailing list
[email protected]
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss

Reply via email to