programdemos/macros.xtl

Macros write source for you: a call "left" n_ame< "right" is replaced, before the program is checked, by the source the macro writes from the two texts. Run it with ./demos/macros.xtl (or xetal run): it prints what the system macros give, then a macro library's checks; a failed a_ssert< goes to standard error. Read each call beside its expansion, which "xetal expand demos/macros.xtl" shows.

source · imports m: lib/Macros.xtlm

System macros

x : Int

value · line 13

The number the conditions below test: negative, so x > 0 is false.

x ← -3

ᵘm̲ax/ : Num a => a -> a

function · line 22

u:m_ax/ v, u:m_in/ v: the largest and smallest item of v, written by e_ach<, one statement per word with $w replaced by the word.

"m_ax m_in" e̲ach< "u:$w/ := { '$w r_/ _r }"
e̲ach< expands to
ᵘm̲ax/ ← { 'm̲ax r̲/ ⍵ }
ᵘm̲in/ ← { 'm̲in r̲/ ⍵ }

ᵘm̲in/ : Num a => a -> a

function · line 22

u:m_ax/ v, u:m_in/ v: the largest and smallest item of v, written by e_ach<, one statement per word with $w replaced by the word.

"m_ax m_in" e̲ach< "u:$w/ := { '$w r_/ _r }"
e̲ach< expands to
ᵘm̲ax/ ← { 'm̲ax r̲/ ⍵ }
ᵘm̲in/ ← { 'm̲in r̲/ ⍵ }

Macros of your own

ᵘs̲quare : Num a => a -> a

function · line 38

u:s_quare x: x times x, defined by the m:d_ef< macro.

"s_quare" ᵐd̲ef< "_r * _r"
ᵐd̲ef< expands to
ᵘs̲quare ← { ⍵ × ⍵ }