This section describes the statements.
statement break_statement call_statement def_statement disrupt_statement do_statement if_statement log_statement return_statement send_statement set_statement use_statement var_statement
statements statement more_statements
more_statements
""
linebreak statement more_statements
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 ':'
space expression
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 set
statement. If the value is mutable,
then the value's members or elements may be changed with set
statement.
(def
applies to variables.
stone
applies to values.)
The def
statement can not appear in an if
or do
.
Variables must be defined before they are used.
Example:
def pi: 3.1415926535897932 def stack: [] set stack[]: pi # Push pi onto the stack. # stack is [3.1415926535897932] # stack has been modified set stack: [] # disrupt: stack can not be replaced.
disrupt
statementdisrupt_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 for loops with the same label so long as they are not nested in each other.
Example:
do set factor: factor * second set progress: (factor / divisor) + result if result = progress \/ progress = null break fi set result: progress set 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" set last_name: "Howard" else if first_name = "Larry" set last_name: "Fine" else set last_name: "(unknown)" fi
The if
statement can be nested.
Example:
if fee if fie set ok: fee fi else set ok: fie fi
The else if
form makes it possible to have alternatives without deep indentation.
Example:
if character(list[at].op) = "j" set list[at].yz: list[at].yz - 1 else if list[at].op = "opx" set list[at].yz: list[at].yz + 1 fi set 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.
Named logs can include
debug emergency error failure feature normal precondition postcondition probe trace
If 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 implicitly by falling
thru the bottom.
Example:
def double: ƒ (number) { return number * 2 } def disrupt: ƒ () { set defcon: 1 call launch_all_missiles() return null }
send
statement
send_statement
"send"
space expression ':'
space expression callback
callback
""
':'
space expression
The send
statement sends a message to another process. The left expression must resolve to a process 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 be stone and 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 processes.
Example:
send server: message
set
statement
set_statement
"set"
space set_value ':'
space expression optional_appendix
set_value name optional_set_value_suffix
optional_set_value_suffix
""
set_value_suffix
set_value_suffix
appendix
'.'
name optional_set_value_suffix
'['
expression ']'
optional_set_value_suffix
invocation set_value_suffix
optional_appendix
""
appendix
appendix
"[]"
The set
statement is the instrument of mutation. It can
var
statement.null
.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 process 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. Standard modules do not require a locator.
The modules are stored in the misty module database, which contains the standard modules which are located with the name form, and the extra module, which 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 (processes 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 process 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 set
statement. The var
statement can not appear in an if
or do
.
Variables must be defined before they are used.
Example:
var first_name: "" var last_name: "" var node_nr: 0