Currently, the only conditional in TOM is the if
else
conditional. (Other languages provide things like switch
statements; which haven't found their way to TOM yet.)
if_expression: `if' tuple expression [`else' expression] ;
The tuple
must be a single-element tuple with a boolean
type. If it evaluates to the truth, the value of the if_expression
becomes the value of the first expression
, otherwise, the value
of the whole expression becomes the value of the expression
in
the else
branch. If the else
branch is omitted, its value
is the default value for the type of the if_expression
. If the types
of the first and second expression
do not match, the type of the
whole if_expression
is void.
loop_expression: while_expression | do_expression | for_expression ;
A loop_expression
causes iterative evaluation of an expression. Each
loop construct is a simple syntactical variation of the others.
while_expression: `while' tuple body ; body: expression ;
The tuple
must have a boolean type. If it evaluates to
TRUE
the body
is evaluated; this is repeated until the
tuple
no longer evaluates to TRUE
.
The type of the while loop is the type of the body
expression.
Its value is the value of the body
the last time it was
evaluated. If the body is never evaluated, the value of the loop is the
default value for the type.
do_expression: `do' body `while' tuple ;
This do-loop is similar to the while-loop except that the tuple
is only evaluated after the body
is evaluated, i.e. the
body
is guaranteed to be evaluated at least once. The type of
the do loop is the type of the body
. Its value is the value of
the body
the last time it was evaluated.
for_expression: `for' `(' [expression] `;' [expression] `;' [expression] `)' body ;
The for loop is pure syntactic sugar. The loop for (a; b; c) d
has exactly the same meaning as
{ { a' } while (b') { typeof (d) d' = d; { c' } d' } }
where the b'
is TRUE
if b
is empty. Similarly, the
a'
and c'
are void
if a
and c
are
empty, respectively. Note that the typeof
type operator is not
actually available in TOM.
Go to the first, previous, next, last section, table of contents.