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.

Anonymous symbols

An anonymous 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!" }
}

Declared symbols

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

symbol Banana

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 keys

It is efficient to use symbols as keys in Maps or on Entities. They can be accessed using . or [].

pub symbol Banana
pub symbol Kiwifruit

const FruitColors = {
Banana = "yellow",
Kiwifruit = "green",
}

pub fn Example() {
Transmission {
"Bananas are " + FruitColors.Banana + ", "
"and kiwifruits are " + FruitColors[Kiwifruit]
}
}