Misty Programming Language:


This section describes the statements.

statements statement more_statements

more_statements "" linebreak statements

statement call_statement def_statement fail_statement if_statement return_statement send_statement set_statement var_statement

The call statement

call_statement "call" space expression invocation

The call statement invokes a function and ignores the return value.

The def statement

def_statement "def" space def_body

def_body name ':' space expression function

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


def pi: 3.1415926535897932
def stack: []
set stack[]: pi      # Push pi onto the stack.
                     # stack is [3.1415926535897932]
                     # stack has been modified
set stack: []        # failure: stack can not be replaced.

The fail statement

fail_statement "fail"

The fail statement causes the function to fail, sending control to a failure handler.

The fail statement causes control to go to the failure part of the function or the enclosing module. If control was already in the failure part, or if there is no failure part, then control goes to the most recent function in the calling chain that has an failure part. See Functions.

The if statement

if_statement "if" space expression consequence else_clause

consequence indent statements outdent

else_clause "" "else" else_consequence

else_consequence space if_statement consequence


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 a
    if b
        set ok: x
    set ok: y

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


if char list[k].op = "j"
    set list[k].yz: list[k].yz - 1
else if list[k].op = "opx"
    set list[k].yz: list[k].yz + 1
set k: k + 1

The if statement creates forks in the control flow of a function. An if statement can not contain var and def statements.

The return statement

return_statement "return" 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 recursion optimization might be performed.

An explicit return is required. A function may not return implicitly by falling through the bottom.


def double: ƒ number {
    return number * 2

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

The send statement

send_statement "send" expression ':' space expression callback

callback "" ':' space expression

The send statement sends a message to another process. The left expression must resolve to an actor object or a message object. The right expression is a record containing the message. The nessage 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.

See actors.


send server: message

The set statement

set_statement "set" space set_value ':' space expression optional_appendix

set_value variable 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

The var statement

var_statement "var" space name var_initialization

var_initialization "" ':' space expression

The var statement creates a variable in the current function scope. If the variable is not explicitly initialized, then it is given the null value. The value of a variable can be replaced by the set statement.


var first_name
var last_name
var node_nr: 0