These reference chapters comprehensively describe the Acorn language. They assume the reader has some familiarity with programming languages as well as how an Acorn program is built up from basic tokens. For a gentler introduction to the language, seek out an Acorn Guide.

Values, Collections, Methods and Types

Before getting into the details, let's introduce some key concepts:

These concepts are deeply intertwined: Every value has a type. Every type is a collection of properties. A property can hold a method. Every method operates on values. Every method and type is itself a value.

Term

The term is the basic building block for an expression. A term can be one of the following: a literal, a variable, or a pseudo-variable (e.g., 'this', 'self' or '...'). With the exception of the splat ('...'), a simple term references a single stored value.

Literal

A literal is a specific unchangeable value, as represented by a number token, symbol or text token, or the reserved names null, true or false. For example (with comments to indicate each literal's type):

123     # Integer
3.4     # Float
"Hello" # Text
'sum'   # Symbol
false   # Bool
null    # Null (represents the absence of a value)

Note Text literals are flagged as read-only. Any attempt to modify them fails. This ensures the literal can never be corrupted by any downstream method.

Pseudo-variables: self, this, context, selfmethod, baseurl and ...

These pseudo-variables look like variables, but are not, as their value is managed by Acorn based on the context where they are encountered. Programs cannot change their value.

Variable

A variable holds a single value. A variable's value is set, modified and retrieved using its name. A variable's value may be changed as often as desired. Acorn does not enforce or restrict what type of value a variable can hold.

Variables are always represented with a non-reserved name token.

Variable Assignment

The value of a variable is set using an assignment expression:

a = 3.4     # a's value is now 3.4
b = 'abc'   # b's value is now the symbol 'abc'
a = b       # changes a's value to the symbol 'abc'
b = true    # changes b's value to the literal true

Any variable to the left of the assignment operator '=' sets the variable's value. A variable found anywhere else retrieves (gets) the value of the variable.

Parallel Assignment

There are several situations where it is helpful to assign multiple values to multiple variables:

# Swap the variable values for a and b
a,b = b,a

# Capture multiple return values from a method,
# such as destructuring the values held by a collection
x,y,z = position.unpack

# Obtain certain values from the splat
template, val1, val2 = ...

Variable Scope

A variable's value is stored within a larger collection of values, which we call its scope. A variable's scope is determined by the first character of the variable name:

_