Standard Library — Specification
Metanotation
A combination of the following metalanguages and metalinguistic formalisms is used in the standard library specification:
- plain English,
- basic mathematical notation,
- (regular) tree grammars,
- MANOOL expressions with syntactic placeholders (also known as metalinguistic variables or metavariables, for short),
- patterns matching MANOOL r-value expressions (namely, operation invocations), with argument placeholders intended to match invocation arguments, augmented with data type annotations where it makes sense,
- MANOOL expressions with argument placeholders (i.e., expression templates).
The standard library specification contains some introductory explanations in plain English followed by entries, each one describing a MANOOL feature or a group of related features. An entry begins with either a tree grammar or an invocation pattern; a semantic description is then provided.
Tree grammars
A tree grammar resembles a traditional formal grammar, but instead of describing a set of strings it describes a set of terms (i.e, trees). That is, in place of string concatenation, term formation is used in the process of derivation. Tree grammars are always qualified as regular because they also resemble traditional regular grammars due to similar fundamental properties they have (which is anyway irrelevant for our purposes).
The following is an example of a tree regular grammar (describing if
special forms):
<if form> -> {if <cond> then <body> else <alt body>[0] <alt body>[1] ... <alt body>[n-1]}
<cond> -> <form>
<body> -> <form>
<alt body> -> <form>
<alt body>[0] <alt body>[1] ... <alt body>[n-1]
means repetition 1 — n
times of items matching <alt body>
, whereas
<alt body>[0] ... <alt body>[n-1]
would mean repetition just 0 — n
times.
Expressions with syntactic placeholders
An example of an expression template with syntactic placeholders (used in the semantic specification for an if
special form):
{if <cond> then {do <body>[0]; ...; <body>[n-1]} else Nil}
<body>[0] ... <body>[n-1]
means repetition of all matches according to the corresponding tree grammar.
Invocation patterns
Examples of invocation patterns:
-
The following is an invocation pattern with an argument placeholder
object
and a result type specified after=>
:IsI48[object] => Boolean
-
And the following is a similar invocation pattern where an argument placeholder
s
is followed by a type annotationString
after:
:I48[s:String] => Integer
-
Sometimes concrete values may be specified instead of argument placeholders and result types:
Order[Nil; Nil] => 0
-
Dispatching arguments of polymorphic operations do not need type annotations; the type
Integer
is assumed here for the argument placeholderx
:x + y:Integer => Integer
-
Results may be sometimes named to reinforce clarity:
~x => minus-x:Integer
Expression templates with argument placeholders
Example of an expression template with argument placeholders x
and y
(from the specification of Rem
for Integer
):
{unless 0 <> y signal Undefined else x - x / y * y}