Misty Programming Language:


This section describes the statements.

statement break_statement call_statement def_statement disrupt_statement do_statement if_statement log_statement op_statement return_statement send_statement set_statement use_statement var_statement

statements statement more_statements

more_statements "" linebreak statement more_statements

The break statement

break_statement "break" do_label

The break statement is used to break out of loops.

The 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.

The def statement

def_statement "def" space def_clause

def_clause name ':' space expression function_literal

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. 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: ƒ double (number) (number + number)
def ƒ double (number) (number + number)

Variables must be defined before they are used.


def pi: 3.1415926535897932

The 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.

The 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.


    set factor: factor * second
    set progress: (factor / divisor) + result
    if result = progress \/ progress = null
    set result: progress
    set divisor: divisor + 1

The if statement

if_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


if first_name = "Curly" \/ first_name = "Moe" \/ first_name = "Shemp"
    set last_name: "Howard"
else if first_name = "Larry"
    set last_name: "Fine"
    set last_name: "(unknown)"

The if statement can be nested.


if fee
    if fie
        set ok: fee
    set ok: fie

The else if form makes it possible to have alternatives without deep indentation.


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
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.

The 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:

debug disaster emergency error failure feature hygiene maintenance normal probe spam trace trivial

It is usually good to log before disrupt. Logging does not change the behavior of a program.

See logging.


log debug: "index" ≈ index

The op statement

op_statement "op" space name indent statements outdent "po"

The op statement identifies a block of statements that can optionally be included in the program or module. The compiler can be configured to only enable certain optional statements. The name of a group of optional statements can be any name.

The statements must be syntactically correct even if the statements are not included. The statements must not include def, var, or use. Uses of op include


op check
    if not(reduce(
        ƒ (zeroth, wunth) (zeroth /\ number?(wunth))
        log type: "arg is not an array of numbers"

The 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.


def double: ƒ (number) {
    return number * 2

def disrupt: ƒ () {
    set defcon: 1
    call launch_all_missiles()
    return null

The 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 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.


send server: message

The set statement

set_statement "set" space name optional_set_value_suffix ':' space expression

optional_set_value_suffix "" set_value_suffix

set_value_suffix '.' name optional_set_value_suffix '[' expression ']' optional_set_value_suffix invocation set_value_suffix

The set statement is the instrument of mutation. It can

The 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 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 (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.

The var statement

var_statement "var" space var_clause

var_clause name ':' space expression function_literal

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.

If the var 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:

var double: ƒ double (number) (number + number)
var ƒ double (number) (number + number)

Variables must be defined before they are used or set.


var first_name: ""
var last_name: ""
var node_nr: 0