A Portable Scheme Module System

Understandability: The implementation avoids wizardry and should be accessible to anyone who knows the language

Portability: One system that can be used across multiple implementations

The way it works is this:

You have a file (say, utils.scm) with Scheme code in it that implements stuff that you want to live in the same module.

You create another file (utils.mod, but that extension is easy to change) which lists the procedures and syntax you want to export.

The load-module procedure reads utils.scm, rewriting unexported procedure names such that only the procedures you want exported show up at the top-level. Everything else gets rewritten during load-time as an ignorable “gensym” of the form %--gensym-utils-random-integer-8190504171, where “utils” is the module name, and “random-integer” is the procedure internal to your module.

The module file format is very simple:

(define-module utils
(exports random-integer atom? take))

The module system exports one procedure: load-module. Run it like so to get the procedures from the aforementioned hypothetical utils package into your environment: