Language
Language Tour
Everything you need to write real Zornux programs, one idea at a time.
Comments
A comment starts with # and runs to the end of the line.
# This whole line is a comment.
create age = 16 # so is this trailing note
Variables
Declare a value with create. Bind it with as or
= (they are interchangeable). Reassign an existing value with
=.
create name as "Alice"
create age = 16
create fruits as ["apple", "banana", "orange"]
age = age + 1
Built-in types
Zornux is strongly typed — values keep their kind and aren't silently mixed.
| Type | Description | Looks like |
|---|---|---|
Number | Integer or decimal | 42, 3.14 |
Text | Unicode string | "hello" |
Truth | Boolean | true, false |
List | Ordered, immutable sequence (operations return a new list) | ["a", "b"] |
Nothing | The absence of a value | nothing |
Number + Text is an error, not a silent conversion. The + operator adds two numbers or joins two texts — both sides must match. And only a Truth value can be a condition.
Operators
Arithmetic uses the usual symbols; comparisons and logic read as English words.
create total = price + tax
create share = total / people
create rest = 10 modulo 3 # remainder
create ok = age is greater than or equal to 18 and has_ticket
create no = order is not equal to nothing
| Phrase | Means |
|---|---|
is / is equal to | equal |
is not / is not equal to | not equal |
is less than | < |
is greater than | > |
is less than or equal to | ≤ |
is greater than or equal to | ≥ |
and / or / not | logical and / or / not |
Conditionals
An if can chain with else if and end with a bare else. Close it with end.
if age is less than 18
show "You are a minor."
else if age is less than 65
show "You are an adult."
else
show "You are a senior."
end
Loops
Three loops cover almost everything — a counted loop, a collection loop, and a conditional loop.
repeat 5 times
show "Hello World!"
end
for each fruit in fruits
show fruit
end
create count = 0
while count is less than 3
show "count is " + count
count = count + 1
end
Functions
A function is a reusable piece of logic. Parameters are introduced
with with; return a value with give back.
function calculate_tax with price
create tax = price * 0.1
give back tax
end
function greet with name
give back "Hello, " + name
end
create total = calculate_tax(100)
show greet("Alice")
A function with no give back simply returns nothing. Use a bare give back to return early without a value.
Functions are values
A function can be stored in a variable, passed to another function, and
returned from one. A lambda is the same function written
without a name — the same with, the same give back,
the same end:
create double as function with n
give back n * 2
end
show double(21) # 42
function apply with fn, x
give back fn(x)
end
show apply(double, 5) # 10
show apply(function with n
give back n + 1
end, 5) # 6 — passed inline
That is what makes the list transforms in the standard library work: they take a function and apply it for you.
Default & named arguments
A parameter can carry a default (= value), so callers
may leave it out. And any argument can be passed by name —
name = value — which lets a call explain itself and skip over
defaulted parameters in the middle. Named arguments follow the positional ones.
function connect with host, port = 443, timeout = 30
show "connecting to " + host + ":" + text(port)
end
connect("api.zornux.com") # all positional; port and timeout default
connect("api.zornux.com", timeout = 10) # positional host, then named — port stays 443
connect(host = "api.zornux.com", port = 8080) # all named
Named arguments work on functions, methods, and function values. A positional argument after a named one (ZX0730), an unknown name (ZX0731, with a did-you-mean), a parameter supplied twice (ZX0732), or a required parameter left unfilled (ZX0733) are all caught by zornux check before the program runs. Call built-ins positionally.
That's the core of everyday Zornux. Next, meet the built-in functions in the Standard Library.