Files
lux/examples/behavioral.lux
2026-02-17 06:52:44 -05:00

25 lines
698 B
Plaintext

fn add(a: Int, b: Int): Int is pure = a + b
fn factorial(n: Int): Int is deterministic = if n <= 1 then 1 else n * factorial(n - 1)
fn multiply(a: Int, b: Int): Int is commutative = a * b
fn abs(x: Int): Int is idempotent = if x < 0 then 0 - x else x
let sumResult = add(5, 3)
let factResult = factorial(5)
let productResult = multiply(7, 6)
let absResult = abs(0 - 5)
fn printResults(): Unit with {Console} = {
Console.print("add(5, 3) = " + toString(sumResult))
Console.print("factorial(5) = " + toString(factResult))
Console.print("multiply(7, 6) = " + toString(productResult))
Console.print("abs(-5) = " + toString(absResult))
}
let output = run printResults() with {}