programdemos/higher-order.xtl

Higher-order built-ins: they take quoted functions as operands, as '+ r̲/ v reduces v with plus. Run it with "xetal run demos/higher-order.xtl" (or "./demos/higher-order.xtl"); it prints the result of each line: reductions, a scan, an outer and an inner product, e_ach, c_ompose and s_wap, then the search and order built-ins s_ort, g_rade, u_nique, i_ndexOf and w_here.

source

Reduce and scan

v : Int

value · line 12

v: the vector the reductions, scan and search built-ins work on.

v ← 3 1 4 1 5

Matrices: reduce, outer and inner products

m : Int

value · line 20

m: a 2 by 3 matrix holding 1 to 6, row by row.

m ← 2 3 r̲eshape r̲ange 6

Functions as operands

ᵘs̲ign : (Num a, Num b) => a -> b

function · line 28

u:s_ign x: -1 when x is negative, 0 when it is zero, 1 otherwise.

ᵘs̲ign ← { x → x < 0 ? -1◆ x = 0 ? 0◆ 1 }