Oregami
Repositories/oxedyne/fe2o3

oxedyne/fe2o3/fe2o3_austenite/tests/fixtures/eval/general/code_basics.typ

1.1 KiB, 1 run

created by r1870400018:63878, which is this file's identity for as long as the history lasts, whatever it is later renamed to

download · who wrote it · its history

1// Bindings, destructuring, closures, control flow and operators.
2#let (a, b, ..rest) = (1, 2, 3, 4)
3#let (x: px, y: py) = (x: 10, y: 20)
4#let add(p, q: 5) = p + q
5#let fact(n) = if n <= 1 { 1 } else { n * fact(n - 1) }
6#let acc = { let s = 0; for i in range(10) { s += i }; s }
7#let w = { let n = 0; while n < 7 { n += 2 }; n }
8#let brk = { let out = (); for i in range(10) { if i == 5 { break }; if calc.odd(i) { continue }; out.push(i) }; out }
9#metadata((a, b, rest, px, py)) <probe>
10#metadata((add(1), add(1, q: 2), fact(10), acc, w, brk)) <probe>
11#metadata((7 / 2, 7.0 / 2, -7 / 2, 2 * 3 + 1, "ab" + "cd", "x" * 3, (1, 2) + (3,), (a: 1) + (b: 2))) <probe>
12#metadata((1 < 2, "a" < "b", 1 == 1.0, (1, 2) == (1, 2), not true, true and false, false or true, 2 in (1, 2), "b" in "abc", "k" in (k: 1))) <probe>
13#metadata((type(1), type(1.0), type("s"), type(none), type(auto), type(1pt), type((:)), type(())) .map(str)) <probe>
14#let f = (..args) => args.pos().len() + args.named().len()
15#metadata((f(1, 2, k: 3), (x => x * 2)(4), ((a, b)) => a + b)) <probe>
16#metadata(range(3).map(i => i * i).filter(i => i > 0).fold(0, (s, i) => s + i)) <probe>