O Language/API/Syntax

From OnixOS
Revision as of 07:20, 25 August 2026 by Tedaryum (talk | contribs) (Created page with "= Syntax = == Definitions and expressions == <pre> def answer = 6 * 7 def greeting = "Hello, " + "world!" output(answer) </pre> Statements may be separated with semicolons. Braces delimit blocks, hashes, and scopes. == Functions == <pre> def add = fn(left, right) { return left + right } output(add(2, 3)) </pre> Functions are first-class values and can be passed to <code>map</code>. == Conditions and iteration == Use <code>if</code> and <code>else</code> for br...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Syntax

Definitions and expressions

def answer = 6 * 7
def greeting = "Hello, " + "world!"
output(answer)

Statements may be separated with semicolons. Braces delimit blocks, hashes, and scopes.

Functions

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

output(add(2, 3))

Functions are first-class values and can be passed to map.

Conditions and iteration

Use if and else for branches. Use while and loop for condition-based repetition. Use for with in to iterate arrays and hashes.

Scopes and modules

scope math {
  def double = fn(x) { return x * 2 }
}

output(math->double(4))
load "helpers.olm"

Other parser forms include proc, env, sock, route, signal, eval, async, wait, set, literal, and impl.