O Language/Getting Started/Language Basics: Difference between revisions
From OnixOS
Created page with "= Language Basics = == Values and definitions == Use <code>def</code> to bind a value to a name. O Language supports numbers, text, booleans, arrays, hashes, and functions. <pre> def answer = 6 * 7 def greeting = "Hello, world!" def enabled = true def colors = ["red", "blue"] def user = {"name": "Ada"} output(answer) </pre> == Functions == Functions are values. Define one with <code>fn</code>, return a value with <code>return</code>, and call it by name. <pre> def..." |
m Protected "O Language/Getting Started/Language Basics" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) |
(No difference)
| |
Latest revision as of 07:30, 25 August 2026
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.
