macro libraryuserlibs/Repeat.xtlm
A macro library of your own (userlibs/, found as libraries of your own are): statements written as many times as you ask, when the program is expanded, a loop unrolled at compile time. Import it with an alias of your choice, "r:" u_se< "Repeat", and see what a program becomes with xetal expand FILE.
Repeating statements
ᵐt̲imes< : Char -> Char -> Char
The statements on the right, written the number of times on the left, one copy per line; it stands as a statement of its own. A count below 1 is refused when the program is expanded.
ʳ⁼u̲se< "Repeat"
"3" ʳt̲imes< "\"hip hip\"" hip hip hip hip hip hip
ᵐt̲imes< ← { count body → n̲ot ⎕S̲TATEMENT @ ? "misplaced-macro call" ⎕R̲EJECT "r:t_imes< writes statements: it stands as a statement of its own" k ← f̲loor f̲irst (n̲umbers count) c̲at 0.0 k < 1 ? "bad-macro-argument left" ⎕R̲EJECT "r:t_imes< writes its statements 1 or more times" k ʰc̲opies body }
Used in: demos/user-macros.xtl:12, x