On this page
These examples use the interpreter grammar at source revision eb2301c. Save a block as a .ola file and run it with olang run FILE.ola. The lexer treats # as end-of-input, so the code blocks contain no source comments.
For a step-by-step introduction to the language and its runtime APIs, start with Using O Language.
Values and output
def project = "OnixOS"
def base = "Arch Linux"
def profiles = ["Core", "KDE", "GNOME"]
output(project + " is based on " + base)
output("First profile: " + profiles[0])
Functions
def add = fn(left, right) {
return left + right
}
output("5 + 3 = " + itostr(add(5, 3)))
Hash lookup
def release = {"project": "OnixOS", "license": "open source"}
output(release["project"])
output(release["license"])
Branch on a value
def profile = "KDE"
if (profile == "KDE") {
output("This image uses the Calamares installer.")
} else {
output("Read the selected profile's installation guide.")
}
Iterate through an array
def profiles = ["Core", "KDE", "GNOME"]
for (profiles in index, name) {
output(itostr(index) + ": " + name)
}
The for form binds the index and value in the current environment. If code needs a reusable helper, place it in another source file and load it with a path relative to the process working directory; see syntax and file loading.
The upstream repository’s older docs/examples.md includes colon-indented blocks, bare assignments and comments that the current lexer/parser do not support. The source-specific examples here are intentionally narrower.