Programming Language for Old Timers


by David A. Moon
February 2006 .. September 2008

Comments and criticisms to dave underscore moon atsign alum dot mit dot edu.


Previous page   Table of Contents   Next page


Modules

A module maps names to definitions, which can be fixed or assignable. Most definition statements create fixed definitions. def name := value creates an assignable definition.

defmodule creates a definition whose name is the module name prefixed by @. Generally references to a module omit the @. Unless the module name contains an embedded @, this definition is defined in the current module. When the module name has only a trailing @, the definition is in the root module.

An embedded @ within a name indicates a name-in-module. It is right associative. a@b means variable a in the module that is the value of @b in the current module. a@b@c means variable a in the module that is the value of variable @b in the module that is the value of variable @c in the current module. A trailing @ means the root module; it does not mean the module that is the value of the variable @ in the current module. Thus @a@ means the variable @a in the root module.

This idea avoids a separate naming system for modules (they are just named by definitions), but avoids name conflicts by using the @ prefix convention. Name conflicts in the root module can be minimized by using hierarchical module naming.

The standard module PLOT contains all the standard definitions of the language, including definitions of standard modules such as PLOT and COMPILER. Unless overridden, a module created by defmodule imports all the definitions exported by PLOT and thus has the standard definitions of the language directly available to it and can refer to xyz in the compiler module by xyz@compiler rather than xyz@compiler@.

A module object remembers its name. When doing separate compilation, references to the module are written into the fasl file using this name. When the fasl file is loaded, the corresponding runtime module object can be located as the definition of this name.

When doing separate compilation, the compiler can create a substitute root module which is populated with a copy of the basic definitions needed. This can prevent definitions in the program being compiled from clobbering definitions used by the compiler.

A program can contain the token module: and an expression evaluated in the current module whose value is the module containing the rest of the program. The expression can be a defmodule or a module name (with the @ prefix). Prior to the first module: token in a program, the current module is a "default user" module that imports all the definitions exported by PLOT.

A module can export definitions and can import definitions from other modules, maybe with renaming. A set of exports can be specified as a string pattern and all definitions whose name matches the pattern will be exported. Imports are resolved dynamically so new exports can be added at any time and will be available as imports in dependent modules for future parsing or linking.

A program can contain the token export: and any module-level definitions named or defined by the following expression will be exported from the current module, except any names after the first that start with _ are not exported; this allows putting export: in front of a defclass to export the class, the constructor, and any public slots, but not private slots. Using export: may be preferable to listing exports individually in defmodule.


Previous page   Table of Contents   Next page