slovo/docs/language/examples/speculative/factorial.slo
2026-05-22 08:38:43 +02:00

22 lines
496 B
Plaintext

; status: design/speculative
; Uses recursive calls, `<=`, `*`, and `-` beyond the current strict
; compiler-supported subset. Value-producing `if` and top-level `test` are now
; promoted, but this full example remains speculative.
(module factorial)
(fn factorial ((n i32)) -> i32
(if (<= n 1)
1
(* n (factorial (- n 1)))))
(test "factorial of zero"
(= (factorial 0) 1))
(test "factorial of five"
(= (factorial 5) 120))
(fn main () -> i32
(print_i32 (factorial 5))
0)