Skip to content
Documentation out of dateLearn more

The New Module System

New

STELF’s old module system, outside of standard ML, is quite weak. The new module system is designed to be a true module system, which not only prevents name collisions but also allows for abstractions. There are three main features of the new module system:

  1. Scopes, which allow name collisions to be avoided
  2. Macros, which allow for abstraction and code reuse
  3. Groups, which allow for code to be published as a library

Scopes are a way to avoid name collisions as well as to structure code. These allow us to namespace our code. As a preliminary, there is a command that is essientally neccassary for scopes, that being %{ ... %}

Sequences

The command %{ ... %} allows us to turn mutiple commands into just one. The syntax for it is a little special, due to the fact that:

  1. Commands which normally can only appear in the top level can now appear inside of it
  2. It can be nested

These are handled as follows1: There are two seperate commands, %{ and %}, the first one, %{, stops parsing the input and then restarts the parsing as if at the top of a file. If at any point the parser encounters a %}, it proceeds to stop parsing. If this happens without %{, this is an error. Otherwise, the %{ finally returns as a single command containing the entierity of the input parsed seperately. Parsing then continues as normal after the %}, using any state changes inside %{ ... %} as appropriate. This can be nested, with the nested calls going onto a stack.

%scope %open %require

%macro NUM name CMD %0, %1 etc

%use NAME (ARGS...)

%data NAME SORT_ARGS... %where ... -> %sort NAME SORT_ARGS... %. %scope NAME ...

  1. The parsing dosen’t actually work like this, but its easier to understand it this way