ilusm.dev
Reference

Operators

Every operator in ilusm - arithmetic, comparison, logic, ranges, pipelines, and optional chaining.

Arithmetic

OperatorWhat it doesExample
+Add numbers, or concatenate strings1 + 23, "a" + "b""ab"
-Subtract10 - 37
*Multiply4 * 520
/Divide10 / 42.5
x = 10 + 5    # 15
y = x * 2     # 30
s = "hello" + " " + "world"   # "hello world"

Comparison

OperatorWhat it does
==Equal
!=Not equal
<Less than
<=Less than or equal
>Greater than
>=Greater than or equal
prn 1 == 1     # tru
prn 1 != 2     # tru
prn 5 > 3      # tru
prn "a" == "a" # tru

Logic

Logic operators are value-returning and short-circuit. They don't always return a boolean - they return one of their operands.

OperatorWhat it does
andReturns the first falsy value, or the last value if all are truthy
orReturns the first truthy value, or the last value if all are falsy
!Negates - always returns tru or fls
# or - great for default values
name = user_input or "anonymous"
port = cfg.port or 8080

# and - conditional chaining
result = ok and compute()

# ! - negation
prn !tru   # fls
prn !nil   # tru
prn !0     # tru (0 is falsy)

Range - ..

Creates an inclusive range of numbers for use in loops. Works ascending or descending.

i <- 0..4:
    prn i    # prints 0, 1, 2, 3, 4

i <- 3..0:
    prn i    # prints 3, 2, 1, 0

# Single value
i <- 5..5:
    prn i    # prints 5

Pipeline - |

| has two uses in ilusm:

1. else branch in if

msg = if ok: "yes" | "no"
if x > 0: prn "positive" | prn "not positive"

2. Expression pipeline

Outside of if, | threads the left value into the right as the first argument:

use trl

xs = [3, 1, 4, 1, 5]
xs | trl.srt     # sorted copy
xs | trl.rev     # reversed copy

dbl(x) = x * 2
xs | trl.map(dbl)    # [6, 2, 8, 2, 10]

# Chain multiple steps
xs | trl.fil(\(x) x > 2) | trl.map(dbl)

Pipeline stage shorthand - no trl. prefix needed after |:

xs | map \(x) x * 2
xs | fil \(x) x > 0
xs | srt

Field chain on the left value:

cfg | .host    # same as cfg.host

Optional chaining - ?. and ?[

Access fields or indices safely without crashing on nil.

usr = {info: {name: "ibot"}}

prn usr?.info?.name    # "ibot"
prn usr?.missing?.key  # nil  (no crash)

xs = [1, 2, 3]
prn xs?[0]    # 1
prn xs?[99]   # nil (out of bounds, no crash)

# Useful with or for defaults
host = cfg?.db?.host or "localhost"

Loop bind - <-

Used in for-style loops to bind each element:

x <- [10, 20, 30]:
    prn x

i <- 0..2:
    prn i