Misty Programming Language:

Introduction

Public Domain 2024 Douglas Crockford

The Misty Programming Language is a dynamic, general-purpose, transitional, secure, distributed process language. It has a gentle syntax that is intended to benefit students, as well as advanced features such as capability security and lambdas with lexical scoping.

The grammar of the language is expressed in McKeeman Form.

Space

The language is quite strict in its use of spaces and indentation. In most programming languages, code spacing and formatting are underspecified, which leads to many incompatible conventions of style, some promoting bug formation, and all promoting time-wasting arguments, incompatibilities, and hurt feelings. Misty instead allows only one convention which is strictly enforced. This liberates programmers to focus their attention on more important matters.

Indentation is in increments of 4 spaces. The McKeeman Form is extended by three special rules to make this possible:

indentation The spaces required by the current nesting.

increase_indentation Append four spaces to the indentation.

decrease_indentation Remove four spaces from the indentation.

The indentation is the number of spaces required at the beginning of a line as determined by its nesting level.

indent increase_indentation linebreak

outdent decrease_indentation linebreak

The linebreak rule allows the insertion of a comment, ends the line, and checks the indentation of the next line. Multiple comments and blank lines may appear wherever a line can end.

linebreak optional_comment linefeed more_linebreaks

more_linebreaks linebreak indentation

space ' '

linefeed '000A'

There are many places where the language expects an end of line, such as at the end of a statement.

Misty is strict about whitespace in order to eliminate the need for, debate over, and circumvention of coding standards. Misty starts with the pretty convention of JSON formatting. For example, JSON allows this compact JSON text

{"one":1,"array":[1,2,3],"text":"hello"}

to be presented more pleasingly as

{
    "one": 1,
    "array": [
        1,
        2,
        3
    ],
    "text": "hello"
}

Misty record literals take this further by eliminating the comma at the end of a line, and eliminating quotes on field names in most cases.

{
    one: 1
    array: [
        1
        2
        3
    ]
    text: "hello"
}

Misty uses the same convention with (left paren and )right paren in argument lists and expressions. In an open argument list, each argument goes on its own line and the commas between the arguments are eliminated.

my_button.on(
    "click"
    ƒ (event) {
        call event.done()
        call take_action()
    }
)

In complex expressions, parens can allow a line break. In this form, expressions may be broken before some operators. (See operators.)

def atan: ƒ (slope) (
    math.sine(
        slope
        / (math.sqrt(
            slope
            * slope
        ) + 1)
    )
)

set progress: (
    result
    + (radicand / result)
) / 2

Comments

A comment begins with an #octothrope and ends with the end of the line. Comments are used to provide context and motivation to help humans understand the programming. The Misty System strictly ignores all comments.

optional_comment "" spaces '#' comment_characters

spaces "" space spaces

comment_characters "" comment_character comment_characters

comment_character '0020' . '10FFFF'

Names

Names are used to identify functions, parameters, fields, variables, modules, and programs. A name starts with a letter. A name may contain any number of letters and digits. A name may contain _underbar and $dollar sign as separators. Names may end with ?question mark which is used to indicate predicate functions and truth values.

name letter subsequent

subsequent "" '?' letter_or_digit subsequent '_' letter_or_digit subsequent '$' letter_or_digit subsequent

letter 'A' . 'Z' 'a' . 'z'

digit '0' . '9'

letter_or_digit letter digit

There are no reserved words.

Purity

The Misty language strives for, but does not achieve, purity. It is a transitional language, so mutation and side-effects are tolerated, but not encouraged. Mutation is only allowed in the set statement. The word set is required in the statement. This allows for using = equal sign correctly as the equality operator.

When calling a function only for its side-effects, the call statement must be used.

This is quite different than conventional languages whose syntax is optimized for mutation and side-effects. For example, JavaScript has 20 assignment operators if you count ++ and -- twice, which you should, and it allows them all to be used in expression position as well as statement position.