programdemos/keys.xtl
Keys: every way X_eTaL is typed. Each line of code appears twice: drawn decorated, as "just pp demos/keys.xtl" shows it, and at the end of the line, after "typed:", exactly the keys you type (a comment is drawn as written, so that text stays plain ASCII). Run it with "xetal run demos/keys.xtl" (or "./demos/keys.xtl") to print each line's result, or "just show demos/keys.xtl" to see each line next to its result. docs/input.md explains each form.
Names and bindings
count! : Int
count!: a variable whose name ends in ! may be bound again (mutation); the ! is part of the name wherever it is used.
count! ← 0 ⍝ typed: count! := 0
ᵘs̲quare : Num a => a -> a
u:s_quare x: x times x. u: puts a name in your program's own namespace (drawn as a raised u). Inside { }, _r is the right argument (drawn as APL's omega).
ᵘs̲quare ← { ⍵ × ⍵ } ⍝ typed: u:s_quare := { _r * _r }
Reduce, scan, rotate and reverse, and their axes
M : Int
M: a matrix of 2 rows and 3 columns, 1 2 3 above 4 5 6. Axis 1 runs down the rows (its length is 2), axis 2 along a row (length 3).
M ← 2 3 r̲eshape r̲ange 6 ⍝ typed: M := 2 3 r_eshape r_ange 6
Functions of your own
ᵘa̲dd : Num a => a -> a -> a
x u:a_dd y: x plus y. Inside { }, _l is the left argument (drawn as APL's alpha) and _r the right: this function takes two arguments.
ᵘa̲dd ← { ⍺ + ⍵ } ⍝ typed: u:a_dd := { _l + _r }
ᵘs̲ign : (Num a, Num b) => a -> b
u:s_ign n: -1, 0 or 1 as n is negative, zero or positive. n -> names the argument n. "c ? r" is a guard: when c holds, the result is r; statements are separated by ; (drawn as a diamond).
ᵘs̲ign ← { n → n < 0 ? -1◆ n = 0 ? 0◆ 1 }