O Language/Getting Started/Language Basics

From OnixOS
Revision as of 07:30, 25 August 2026 by Tedaryum (talk | contribs) (Protected "O Language/Getting Started/Language Basics" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Language Basics

Values and definitions

Use def to bind a value to a name. O Language supports numbers, text, booleans, arrays, hashes, and functions.

def answer = 6 * 7
def greeting = "Hello, world!"
def enabled = true
def colors = ["red", "blue"]
def user = {"name": "Ada"}

output(answer)

Functions

Functions are values. Define one with fn, return a value with return, and call it by name.

def add = fn(left, right) {
  return left + right
}

output(add(2, 3))

Conditions and loops

if (answer >= 42) {
  output("ready")
} else {
  output("not ready")
}

for (colors in index, value) {
  output(value)
}

Use while or loop for condition-based repetition. Use map when a function should be applied to the items in a collection.

Read more

The complete grammar and value model are in Syntax, Tokens and Operators, and Types.