sourcedemos/user-macros.xtl
1⍝!/usr/bin/env xetal
2⍝# A macro library of your own: userlibs/Repeat.xtlm (in the live demo,
3⍝# Repeat.xtlm among your files). It is found as a library of your own
4⍝# is, and its macro r:t_imes< writes statements as many times as you
5⍝# ask, when the program is expanded: a loop unrolled before it runs.
6⍝#
7⍝# Run it with ./demos/user-macros.xtl or "xetal run
8⍝# demos/user-macros.xtl". It prints hip hip three times, hooray, then
9⍝# 32. "xetal expand demos/user-macros.xtl" shows the copies.
10
11ʳ⁼u̲se< "Repeat"
12"3" ʳt̲imes< "\"hip hip\""
13"hooray"
14
15⍝ The copies are ordinary statements, so they can rebind a variable:
16⍝ five doublings, unrolled.
17⍝# The number the five unrolled statements double, from 1 to 32.
18x ← 1
19⍝# Five copies of x := x * 2, written by r:t_imes<.
20"5" ʳt̲imes< "x := x * 2"
21x
ʳt̲imes< expands to
"hip hip" "hip hip" "hip hip"