Overview

Primary expressions: literals, identifiers, parens, lists, maps

Notch source is built out of expressions. The smallest expressions are called primary expressions: integer literals, boolean literals, string literals, null, identifiers, parenthesized expressions, list literals, and map literals.

Literals

Integer literal:

42

Integer literals also accept hexadecimal, binary, and octal prefixes:

0xff      # 255
0b101     # 5
0o77      # 63

Boolean literals:

true
false

Null literal:

null

String literal (single or double quoted):

'hello'
"hello"

Comments

Lines beginning with // are comments and ignored by the parser:

// this is a comment
x = 1   // trailing comments work too

List literal

[1, 2, 3]

A trailing comma is allowed:

[1, 2, 3,]

Map literal

Map keys may be bare identifiers, double-quoted strings, or terse strings prefixed with :.

{foo = 1, bar = 2}
{"foo foo" = 1, bar = 2}
{:foo123 = 1, bar = 2}

Map values can be any expression, including closures:

{foo = \-> "bar"}

Identifiers and parens

Identifiers refer to bindings in the current scope. Parentheses group expressions:

(1 + 2) * 3

See also