Skip to content
Plumlang

Language reference · Section 2

Source text

2.1 Files

A Plumlang source file is UTF-8 text with the extension .plum. A byte order mark at the start is ignored. Line endings may be \n or \r\n.

Code may nest up to 1000 deep: brackets, blocks, types and lambdas inside each other, with each operator of a chain like a + b + c counting one level. Deeper code is a compile error (E0218), never a crash. Other limits, each a compile error: a function, lambda or kind case has at most 255 parameters (E0219); a tree has at most 255 fields with its parents' (E0429); a tree or trait extends trees and traits at most 32 deep (E0428), and never itself (E0427).

2.2 Comments

A comment starts with # and runs to the end of the line.

# A whole-line comment
plant total = 0   # a comment after code

There are no block comments.

2.3 Statements and lines

A statement ends at the end of its line. There are no semicolons.

A statement continues onto the next line when the line ends inside an open (, [ or {, or ends with a binary operator, ,, . or ->:

plant total = price
    + tax
    + shipping

plant names = [
    "Ada",
    "Grace",
]

A trailing comma is allowed in every list of items.

2.4 Identifiers

An identifier starts with a letter or _ and continues with letters, digits and _. Letters are ASCII a–z and A–Z. Identifiers are case-sensitive.

By convention, which the formatter and the linter follow:

Kind Style Example
Variables, functions, fields, modules snake_case total_price, read_file
Constants UPPER_SNAKE_CASE MAX_USERS
Types (tree, trait, kind) PascalCase HttpRequest

A name starting with _ is private to its module or tree (section 9.4).

2.5 Keywords

These words are reserved and cannot be used as identifiers:

Keyword Meaning
plant declare a variable
root declare a constant
branch declare a function or method
tree declare a class
trait declare an interface
kind declare an enumeration
seed import a module
good, bad the boolean values true and false
none the absent value
if, else, match choose
for, in, while, break, continue repeat
return leave a function
and, or, not logic
is type test
as conversion, import alias
self, super the current object, its parent tree
throw, try, catch, finally errors
spawn start a task
weak a non-owning reference

true and false are also accepted as spellings of good and bad, so programs from other languages read naturally. The formatter keeps whichever spelling a file uses.

2.6 Literals

Integers are written in decimal, hexadecimal (0x), octal (0o) or binary (0b). _ may separate digits.

42    1_000_000    0xFF    0o755    0b1010_0101

An integer literal that does not fit in 64 bits is a compile error.

Floats have a . with digits on both sides, an exponent, or both.

3.14    0.5    1e9    6.022e23    2.5e-3

.5 and 5. are not floats; write 0.5 and 5.0.

Booleans are good and bad (or true and false).

Strings are written in double quotes. There is one string syntax.

"Hello"
"Tab:\t, newline:\n, quote: \", backslash: \\"
"Unicode: \u{1F351}"
Escape Meaning
\n \t \r \0 newline, tab, carriage return, NUL
\\ \" backslash, double quote
\{ \} literal braces
\u{XXXX} a Unicode code point, 1 to 6 hex digits

Any other escape is a compile error.

Interpolation: {expression} inside a string is replaced by the expression's text (section 4.10).

plant name = "Ada"
drop("Hello, {name}! 2 + 2 = {2 + 2}")

Multi-line strings use triple quotes. The first newline after the opening """ is dropped, and the indentation of the closing """ is removed from every line:

plant poem = """
    Roses are red,
    Plums are purple.
    """
# poem == "Roses are red,\nPlums are purple.\n"

Lists [1, 2, 3], maps {"a": 1, "b": 2}, and the empty map {:} are described in section 3.4.