Scheme 48 Manual -- The configuration language

Scheme 48 Manual | Contents | In Chapter: Module system
Previous: Introduction | Next: Interfaces

## The configuration language

The configuration language consists of top-level defining forms for modules and interfaces. Its syntax is as follows:

<configuration> | `->` <definition>*
<definition> | `->` `(define-structure <name> <interface> <clause>*)`
| `->` `(define-structures ((<name> <interface>)*) <clause>*)`
| `->` `(define-interface <name> <interface>)`
| `->` `(define-syntax <name> <transformer-spec>)`
<clause> | `->` `(open <structure>*)`
| `->` `(access <name>*)`
| `->` `(begin <program>)`
| `->` `(files <filespec>*)`
| `->` `(optimize <optimize-spec>*)`
| `->` `(for-syntax <clause>*)`
<interface> | `->` `(export <item>*)`
| `->` <name>
| `->` `(compound-interface <interface>*)`
<item> | `->` <name>
| `->` `(<name> <type>)`
| `->` `((<name>*) <type>)`
<structure> | `->` <name>
| `->` `(modify <structure> <modifier>*)`
| `->` `(subset <structure> (<name>*))`
| `->` `(with-prefix <structure> <name>)`
<modifier> | `->` `(expose <name>*)`
| `->` `(hide <name>*)`
| `->` `(rename (<name>0 <name>1)*)`
| `->` `(alias (<name>0 <name>1)*)`
| `->` `(prefix <name>)`

The configuration language.

A `define-structure` form introduces a binding of a name to a structure. A structure is a view on an underlying package which is created according to the clauses of the `define-structure` form. Each structure has an interface that specifies which bindings in the structure's underlying package can be seen via that structure in other packages.

An `open` clause specifies which structures will be opened up for use inside the new package. At least one structure must be specified or else it will be impossible to write any useful programs inside the package, since `define`, `lambda`, `cons`, etc. will be unavailable. Packages typically include `scheme`, which exports all bindings appropriate to Revised5 Scheme, in an `open` clause. For building structures that export structures, there is a `defpackage` package that exports the operators of the configuration language. Many other structures, such as record and hash table facilities, are also available in the Scheme 48 implementation.

The `modify`, `subset`, and `prefix` forms produce new views on existing structures by renaming or hiding exported names. `Subset` returns a new structure that exports only the listed names from its <structure> argument. `With-prefix` returns a new structure that adds <prefix> to each of the names exported by the <structure> argument. For example, if structure `s` exports `a` and `b`, then

>     (subset s (a))

exports only `a` and

>     (with-prefix s p/)

exports `a` as `p/a` and `b` as `p/b`.

Both `subset` and `with-prefix` are simple macros that expand into uses of `modify`, a more general renaming form. In a `modify` structure specification the <command>s are applied to the names exported by <structure> to produce a new set of names for the <structure>'s bindings. `Expose` makes only the listed names visible. `Hide` makes all but the listed names visible. `Rename` makes each <name>0 visible as <name>1 name and not visible as <name>0 , while `alias` makes each <name>0 visible as both <name>0 and <name>1. `Prefix` adds <name> to the beginning of each exported name. The modifiers are applied from right to left. Thus

>     (modify scheme (prefix foo/) (rename (car bus))))

makes `car` available as `foo/bus`..

The package's body is specified by `begin` and/or `files` clauses. `begin` and `files` have the same semantics, except that for `begin` the text is given directly in the package definition, while for `files` the text is stored somewhere in the file system. The body consists of a Scheme program, that is, a sequence of definitions and expressions to be evaluated in order. In practice, we always use `files` in preference to `begin`; `begin` exists mainly for expository purposes.

A name's imported binding may be lexically overridden or shadowed by defining the name using a defining form such as `define` or `define-syntax`. This will create a new binding without having any effect on the binding in the opened package. For example, one can do `(define car 'chevy)` without affecting the binding of the name `car` in the `scheme` package.

Assignments (using `set!`) to imported and undefined variables are not allowed. In order to `set!` a top-level variable, the package body must contain a `define` form defining that variable. Applied to bindings from the `scheme` structure, this restriction is compatible with the requirements of the Revised5 Scheme report.

It is an error for two of a package's opened structures to export two different bindings for the same name. However, the current implementation does not check for this situation; a name's binding is always taken from the structure that is listed first within the `open` clause. This may be fixed in the future.

File names in a `files` clause can be symbols, strings, or lists (Maclisp-style "namelists"). A "`.scm`" file type suffix is assumed. Symbols are converted to file names by converting to upper or lower case as appropriate for the host operating system. A namelist is an operating-system-independent way to specify a file obtained from a subdirectory. For example, the namelist `(rts record)` specifies the file `record.scm` in the `rts` subdirectory.

If the `define-structure` form was itself obtained from a file, then file names in `files` clauses are interpreted relative to the directory in which the file containing the `define-structure` form was found. You can't at present put an absolute path name in the `files` list.

Previous: Introduction | Next: Interfaces