recursive countDown macro

daniel daniel <[email protected]>
Newsgroups gmane.comp.gnu.m4.general
Message-ID <CAF5U=uf6UFsLE5BGcm2OdUOWKEmHYce0Ue3eYE3CE=jK71J0ig@mail.gmail.com>
Hi guys,
I felt like writing a recursive countdown macro.

CODE:
define(countDown,`$1
`'ifelse($1,0,,`$0'(`eval'($1 - 1)))')dnl
countDown(10)

OUTPUT:
10
9
8
7
6
5
4
3
2
1
0

DISCUSSION:
In m4, recursion is more readable with ifelse,
where the first argument of ifelse is the
terminating condition. So, in my countDown
macro, the fourth argument of ifelse is a
call to $0 with a nested eval() to subtract
one from the argument and pass the result
as the argument recursively. (The argument
is also printed with a newline at each
iteration).
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.