This section describes the statements.
statement assign_statement break_statement call_statement def_statement disrupt_statement do_statement if_statement log_statement return_statement send_statement use_statement var_statement
statements statement more_statements
more_statements
""
linebreak statement more_statements
assign
statement
assign_statement
"assign"
space name optional_assign_suffix optional_box ':'
space expression optional_box
optional_assign_suffix
""
assign_suffix
assign_suffix
'.'
name optional_assign_suffix
'['
expression ']'
optional_assign_suffix
invocation assign_suffix
optional_box
""
"[]"
The assign
statement is the instrument of mutation. It can replace the value of a variable that was
created by the var
statement.
The assign
statement can also act on values that are mutable.
null
.assign array[]: value
assign variable: array[]
Attempting any of those changes on a stone object will disrupt.
break
statement
break_statement
"break"
do_label
The break
statement is used to break out of loops.
call
statement
call_statement
"call"
space callee
callee
'@'
selection invocation
name activate
activate selection activate subscript activate invocation optional_activate
optional_activate
""
activate
The call
statement invokes a function and ignores the return value.
def
statement
def_statement
"def"
space name def_value
def_value
':'
space expression
input_list space body
The def
statement defines a read-only variable within
the current function. The variable is read-only, but the value it contains
may be mutable. Names that are defined with the def
statement
can not be changed with the assign
statement. If the value is mutable,
then the value's members or elements may be changed with the assign
statement.
The def
statement can not appear in an if
or do
.
If the def
is followed by a function literal, then a read only variable having the same name as the function is created and given the value of the function object. So these two statements do the same thing:
def double: function double (number) (number + number) def double(number) (number + number)
Variables must be defined before they are used. The name may not be used on the right side of the :
colon.
Example:
def pi: 3.1415926535897932
disrupt
statement
disrupt_statement
"disrupt"
The disrupt
statement causes the function to abruptly stop, sending control
to a function's disruption
part.
The disrupt
statement causes control to go to the disruption
part of the function or the enclosing module. If control was already in the disruption
part, or if there is no disruption
part, then control goes
to the most recent function in the calling chain that has a disruption
part.
do
statement
do_statement
"do"
do_label indent statements outdent "od"
do_label
do_label
""
space name
The do
statement executes a list of statements until the loop is broken by break
,
return
, or disrupt
.
Loop labels are in their own name space. A function may contain two or more loops with the same label as long as they are not nested in each other.
Example:
do assign factor: factor * second assign progress: (factor / divisor) + result if result = progress \/ progress = null break fi assign result: progress assign divisor: divisor + 1 od
if
statementif_statement then_clause "fi"
then_clause
"if"
space expression indent statements outdent else_clause
else_clause
""
"else"
else_consequence
else_consequence space then_clause indent statements outdent
Example:
if first_name = "Curly" \/ first_name = "Moe" \/ first_name = "Shemp" assign last_name: "Howard" else if first_name = "Larry" assign last_name: "Fine" else assign last_name: "(unknown)" fi
The if
statement can be nested.
Example:
if fee if fie assign ok: fee fi else assign ok: fie fi
The else if
form makes it possible to have alternatives without deep indentation.
Example:
if character(list[at].op) = "j" assign list[at].yz: list[at].yz - 1 else if list[at].op = "opx" assign list[at].yz: list[at].yz + 1 fi assign at: at + 1
The if
statement creates forks in the control flow of a
function. An if
statement can not contain var
and def
statements.
log
statement
log_statement
"log"
name ':'
space expression
The log
statement may send an expression to the named log. It is used to record information about the execution of the program for later analysis.
If logging to the named log has not been enabled, then the log
statement does nothing. The compiler can be configured to only enable certain logs.
The name of a log can be any name. For example:
compliance debug disaster emergency error failure fatal feature hygiene maintenance normal probe spam test trace trivial violation
A system may block the execution of programs that would attempt to use restricted logs.
It is usually good to log
before disrupt
. Logging does not change the behavior of a program.
See logging.
Example:
log debug: "index" ≈ index
return
statement
return_statement
"return"
return_value
return_value
""
space expression
The return
statement provides for the normal exit of a function
and the specification of its return value. If the expression is a function invocation,
then the tail call optimization might be performed.
If a return value is not provided, then null
is assumed. A function may return null
implicitly by falling
thru the bottom.
Example:
def double(number) { return number * 2 } def abort() { assign defcon: 1 call launch_all_missiles() }
send
statement
send_statement
"send"
space expression ':'
space expression callback
callback
""
':'
space expression
The send
statement sends a message to another actor.
The left expression must resolve to an actor address object or a message object that is expecting a reply because it was sent with a callback. The right expression is a record containing the outgoingmessage. The outgoing message record must not contain functions or patterns or cyclic structures.
If a callback function is included, then the callback function will receive the reply, not the receiver function.
See programs.
Example:
send server: message
use
statement
use
"use"
space name optional_locator
optional_locator
""
':'
space locator
locator text_literal name
The use
statement makes a module available to a program or another module. The return value of the module is bound to the name. An optional locator can be provided for finding the module file in the program shop. Standard modules do not require a locator.
The modules are stored in the program shop, which contains the standard modules that are located with the name form, and the extra modules that are located with the text_literal form. In the text_literal form, it is recommended that the text contain a prefix to indicate the source or usage of the module. Guest code (programs from third parties that are not fully trusted) may be restricted from use of the use
statement, or may have restrictions on which modules they can employ.
The use
statement can not appear in a function or an if
or do
. The use
statement can only appear in the outermost level of an program
or module
.
var
statement
var_statement
"var"
space name ':'
space expression
The var
statement creates a variable in the current function scope.
The value of a variable can be replaced by the assign
statement. The var
statement can not appear in an if
or do
. The name is the name of a new variable in this scope.The expression on the right side of the :
colon gives the initial value of the variable. The name may not be used on the right side of the :
colon.
Variables must be declared before they are used or assigned values. Note that :
expression are not optional.
Examples:
var first_name: "" var last_name: "" var node_nr: 0