Macro primitives |
Macros can be used to define new tags and to build procedural abstractions in style files.
Older versions of TeXmacs used to make a distinction between macros
(all children accessible) and functions (no accessible child). In
modern TeXmacs there are only macros: the accessibility of children is
determined heuristically and can be controlled with
This primitive returns a macro (the TeXmacs analogue of a λ-expression) with n arguments, named after the literal strings var-1 until var-n.
New tags are defined by storing macros in the environment. Most
of the time, macros are stored without scope with
<assign|abbr|<macro|x|<group|x>>>
Storing a
This primitive is used to retrieve the arguments of a macro
within its body. For instance, <
This tag is similar to
When more than one arguments are specified, <
This primitive returns a macro (the TeXmacs analogue of a
λ-expression) capable of taking any number of arguments.
The arguments are stored in the macro variable with name var (a literal string) during the evaluation
of the body. The i-th
individual argument can then be accessed using <
This primitive evaluates to a tree whose root is labeled by root and whose children are the result of applying the macro foo to the children of the macro argument with name var.
By default, the macro foo is applied to all children. If first has been specified, then we rather start at the i-th child of var, where i is the result of evaluating first. If last has been specified to, then we stop at the j-th child of var (the j-th child not being included), where j is the result of evaluating last. In this last case, the arity of the returned tree is therefore j - i.
Stated otherwise,
The
The
<assign|comma-extra|<macro|x|, x>>
<
assign
|
comma-separated
|
<
xmacro
|
args
|
<\concat|
<arg|args|0>
<map-args|comma-extra|concat|args|1>
This primitive evaluates to the tree with the same label as the expansion of the argument var and whose subtrees are the result of the evaluation of the subtrees of the expansion of var.
This primitive is useful to expand macros which are the result
of a computation: it applies the macro which is the result of
the evaluation of foo to the
arguments arg-1 until arg-n.
The
Actually, in the current implementation, foo may either evaluate to a macro or to a literal string which gives the name of a macro. However, we discourage users to rely on the second case.
In the code below, <
<
assign
|
filter
|
<
macro
|
pred
|
t
|
<\if|
<equal|<length|t>|0>
<tuple>
<\merge|
<\if|
<compound|pred|<look-up|t|0>>
<tuple|<look-up|t|0>>
<tuple>
<filter|pred|<range|t|1|<length|t>>>
As an application, we may define a macro <
<assign|evens|<macro|t|<filter|<macro|x|<equal|<mod|x|2>|0>>|t>>>
The arity and children accessibility of tags defined by macros
are determined heuristically by default. The
Returns the label of the tree obtained when evaluating expression.
Returns the label of the tree obtained when evaluating expression.