Skip to content

Symbols

Symbols allows you to define a value or type that can be re-used multiple times by referring to it’s name. A symbol defined with a value can normally be assumed to be a constant (custom runtimes can create variable symbols). Functions and filters assigned to symbols are constants, but will of course generate a value when invoked.

To create a symbol, use the let statement:

let <name>[:<type>][ = <value>]

As you can see, type is optional, and will be inferred by the value. But it’s useful when defining complex values with a known type. For example, imagine that there’s a custom type defined Order, and you’re trying to define a value of said type, allowing the parser to check that your value is correct:

let myOrder: Order = {
orderNumber = 1234
customer = {
customerNumber = 'C1'
name = 'Company Xyz'
}
orderLines = [{
productNumber = 'P1'
description = 'Product 1'
qty = 1
price = 100
}]
}

Custom Types

Complex types can be quite massive and tedious to write. In this case, symbols allows for types to be named so they don’t have to be typed out in full every time. To define a custom type, simply drop the value and only specify the type:

let Order: {
orderNumber: number
customer: {
customerNumber: text
name: text
}
}

Note that the initial uppercase is optional, but it’s a convention in filtrera to write custom type symbols with an initial upper case. This separates a type from a value visually.

Naming Constraints

A symbol name must start with a letter or underscore followed by any number, letters or underscores. These constraints exists to avoid confusion between a literal number and a symbol.

To work around this and be able to use more elaborate symbols, the symbol name can be wrapped in back-ticks name. This allows for even whitespace to be used (although that might not be a good idea):

let `My very long and poetic symbol name` = 1

Keywords

Keywords may be added to the language in newer versions, as well as in custom runtimes. To avoid future conflicts, you can always use back-ticks to indicate that it is indeed a symbol and not a keyword reference.

Another way to avoid future conflicts is to ensure your symbol names contain two or more words, as built-in keywords will always be single words.