Skip to main content

Symbols

A symbol represents a unique identifier. The only other value equal to the symbol is itself. Symbols are a fast and reliable way to identify things. Comparing symbols is much faster than comparing strings, for example.

Inline symbols

An inline symbol can be created anywhere inline using the $ character followed by an identifier. The identifier must begin with a lowercase letter.

let what = $banana
if what == $banana {
Transmission { "You have a banana!" }
}

Inline symbols are global. That is, if the symbol $banana is used in multiple files, they will be equivalent.

Static symbols

A static symbol is created using the symbol keyword followed by an identifier. The identifier must begin with an uppercase letter.

symbol Banana

Static symbols can be declared as public using the pub keyword, which allows them to be accessed from all files in the program. Otherwise they are private and can only be accessed from within the same file. If two private symbols have the same name but are in different files, they are not the same symbol and will not interfere with each other.

pub symbol Banana

Comparing symbols​

Symbols can be compared using the == and != operators.

pub symbol Banana
pub symbol Kiwifruit

pub fn Example(what) {
Transmission {
if what == Banana {
"You have a banana!"
} else if what != Kiwifruit {
"Where is my kiwifruit?"
}
}
}

Symbols as map keys​

Map keys are actually symbols! That is why you can simply use dot notation . to use a symbol to access a field in a Map.

const FruitColors = {
// The following two lines are equivalent:
banana = "yellow",
[$banana] = "yellow",
}

pub fn Example() {
// The following two lines are equivalent:
Print { "Bananas are " + FruitColors.banana }
Print { "Bananas are " + FruitColors[$banana] }
}