Macro expansion |
The main interest of the TeXmacs' style-sheet language is the
possibility to define macros. These come in three flavours: ordinary
macros, macros which take an arbitrary number of arguments and
external macros, whose expansion is computed by
Ordinary macros are usually defined using
<assign|my-macro|<macro|x1|⋯|xn|body>>
After such an assignment,
<my-macro|y1|⋯|yn>
Inside the body of the macro, the
<assign|hello|<macro|name|Hello name, you
look nice today!>>
It is possible to call a macro with less or more arguments than the
expected number. Superfluous arguments are simply ignored. Missing
arguments take the nullary
<
assign
|
hey
|
<
macro
|
first
|
second
|
<\if|
<equal|second|?>
Hey first, you look
lonely today...
Hey first and second, you form a nice couple!
We finally notice that you are allowed to compute with macros, in a similar way as in functional programming, except that our macros are not closures (yet). For instance:
<assign|my-macro-copy|my-macro>
The
<
assign
|
overloaded-hi
|
<
macro
|
name
|
<\compound|
<if|<nice-weather>|happy-hi|sad-hi>
name