Skip to content

Namespaces

Bill Hails edited this page Aug 13, 2024 · 13 revisions

Namespaces are separate files that can be accessed by using the link statement in the let part of a file. For example

let
    link "listutils.fn" as list;
in
    print(list.sort("cba"))

prints "abc"

The as part is not optional, in this example it defines the symbol list to be the namespace populated with the contents of the nominated file. The functions, types and type constructors defined in that file become available by prepending them with the namespace and a dot.

Files to be imported as namespaces must begin with the keyword namespace and consist only of typedefs, functions and declarations at the top-level. No nests or let/in constructs are valid at the top-level of a namespace file. User-defined print functions (see Print) are valid in namespaces.

The path to the file to be linked is initially taken as relative to the parent file, but additional directories to be searched can be supplied on the command line with the --include=dir option.

Utility Libraries

I've started to build out some basic library support using namespaces. Currently there is only listutils.fn and ambutils.fn and you can read about those in the next sections.

Next: List Utils

Clone this wiki locally