sourcedemos/factorial.xtl
1⍝!/usr/bin/env xetal
2⍝# Factorial: recursion with guards, one statement per line. Run it with
3⍝# "xetal run demos/factorial.xtl" (or "./demos/factorial.xtl"); it
4⍝# prints 3628800, the factorial of 10. Read u:f_act for how a guard
5⍝# (c ? r) ends a function early and how a function calls itself.
6
7⍝# n u:f_act: the factorial of n, 1 when n is at most 1, otherwise n
8⍝# times the factorial of n - 1.
9ᵘf̲act ← { n →
10 n ≤ 1 ? 1
11 n × ᵘf̲act n − 1
12}
13ᵘf̲act 10