home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 22 gnu
/
22-gnu.zip
/
fweb140x.zip
/
demos
/
macros.hweb
< prev
next >
Wrap
Text File
|
1993-10-30
|
2KB
|
58 lines
@ Here is a more complete demo of \.{WEB} macro expansions. See the user
manual for discussion of stringizing and token-pasting.
@m P(s) #s = s. /* Display macro and its result. Uses stringize operation. */
@m _A /* A null macro. */
@m _B 2 /* A simple macro. */
@m _C a + b + c /* Slightly more complicated, but no macros on rhs. */
@m _C1 (_A)*(_B)*(_C) /* Macros on rhs. */
@m _D(x) (x)**9 /* Function macro. */
@m _E(x,y) _B*(x)*(y) /* Two arguments, and a macro. */
@m VAR(i,j) var##i_##j /* Token pasting. */
@m RECURSE(a,b) a##b(a,b) /* ANSI's example of possible recursion. */
@m TRIPLE(a,b,c) a##b##c(a,b,c,a##b,a##c,b##c) /* Advanced token pasting. */
/* Recursion through several levels. */
@m _R _W
@m _W _X
@m _X _R
@m _R1(i) _W##i(i) + ar
@m _W1(i) _X##i(i) + _W1(i) + aw
@m _X1(i) _R##i(i) + _X1(i) + ax
@a
/* OBJECT MACROS. */
P(_A) /* Null */
P(_B) /* Simple */
P(_C) /* Ordinary replacement. */
P(_C1) /* Macros on rhs. */
/* FUNCTION MACROS. */
P(_D(x)) /* Basic form of function macro. */
P(_D(2)) /* Evaluation of the macro. */
P(_D(_B)) /* Macro argument as parameter. */
P(_D(_D(_C1))) /* Recursion. */
/* SEVERAL ARGUMENTS. */
P(_E(x,y)) /* Basic form. */
P(_E(2,3)) /* Evaluation. */
P(_E(_D(_B),_C)) /* Macros as parameters. */
P(F(_A,_B,_E(_D(_B),_A))) /* Complicated. */
/* TOKEN PASTING. */
P(VAR(1,2))
P(TRIPLE(a,_C,1))
/* RECURSION. */
P(RECURSE(RE,CURSE)) /* Recursion. */
@#if 0
P(RECURSE(RECURSE,RECURSE)) /* More recursion; invalid form. */
@#endif
P(_R) /* Recursion through several levels. */
P(_R1(1))