Algol 68 Genie: Pragmats, Preludes & Extensions

Option names occasionally change between releases; always check a68g --help for your version.

37.1 Useful command-line options

--help / --version usage and build information (including which optional libraries are present) --check (or --norun) syntax and mode check only --debug / --monitor enter the debugger on errors digits of precision for LONG LONG modes

--heap, --stack, --frame, --handles --quote-stropping / --upper-stropping choose the stropping regime --optimise (-O) / --compile compile units to C for speed on supported platforms (Linux) treat the file as a script (useful with a #! line)

--warnings / --no-warnings, --pedantic Option names occasionally change between releases; always check a68g --help for your version.

37.2 Pragmats

Pragmats (PR ... PR or PRAGMAT ... PRAGMAT) pass instructions to a68g, and can carry options inside the source file. a68g also uses pragmats for textual inclusion of other source files, e.g. PR read "utils.a68" PR (see the manual for the read/include forms supported by your version).

37.3 Preludes and "modules"

The Revised Report defines a standard prelude (modes, operators and procedures such as print, sqrt, whole) and allows library preludes supplied by an implementation, with the user program inserted as a "particular program". It does not define modules or separate compilation. Historically:

ALGOL 68-R offered separate compilation of "segments".

ALGOL 68RS (and a68toc) implemented the Lindsey–Boom modules proposal (DECS, CONTEXT, ACCESS).

a68g relies on its large extended prelude plus textual inclusion for multi-file programs.

The in-development GCC front end (ga68) implements a module system as an extension.

37.4 Language extensions in a68g

a68g implements the Revised Report and adds, among others (check the manual for exact syntax):

Short-circuit Boolean operators ANDF / ORF (also spelled ANDTH / OREL).

UNTIL part in loops (DO ... UNTIL condition OD) and DOWNTO for counting down.

Partial parametrisation of procedures (§31.6).

Multi-precision LONG LONG INT/REAL/COMPL.

Additional operators and procedures for strings, bits, complex numbers, and linear algebra/FFT (when built with the GNU Scientific Library).

37.5 Extended prelude highlights

Examples (availability depends on the build) argc, argv(i), getenv(name), system(command), fork, execve, wait pid, pipe

clock, seconds, utc time, local time char in string, string in string, to upper, to lower, is digit, is alpha style predicates

grep in string(pattern, string, start, end), sub in string(pattern, replacement, string) (POSIX regex) drawing on X11/PostScript/PNG devices via GNU plotutils: draw device, draw move, draw line, draw colour, draw show

random, extra special functions, GSL-based routines curses-based screen procedures PostgreSQL client procedures reading/writing sound files

Example: command-line arguments and environment:

(Run as a68g args.a68 -- one two; the exact numbering of argv includes the interpreter and program names — print them to see.)

Example: regular expressions (POSIX ERE):

grep in string returns 0 on a match and sets the start and end positions.

BEGIN
   print(("argc = ", whole(argc, 0), newline));
   FOR i TO argc DO print(("argv ", whole(i, 0), " = ", argv(i), newline)) OD;
   print(("HOME = ", getenv("HOME"), newline))
END
BEGIN
   STRING text = "Order 66 was issued in year 19 BBY";
   INT start, finish;
   IF grep in string("[0-9]+", text, start, finish) = 0 THEN
      print(("first number: ", text[start:finish], newline))
   FI
END

37.6 Unit compilation

On Linux, a68g -O program.a68 compiles units to C, builds a shared object, and runs it — often several times faster than pure interpretation, with identical semantics and checks.