Metalang99 1.13.3
Full-blown preprocessor metaprogramming
|
Sequences: (x)(y)(z)
.
More...
Go to the source code of this file.
Macros | |
#define | ML99_seqIsEmpty(seq) ML99_call(ML99_seqIsEmpty, seq) |
True iff seq contains no elements (which means an empty preprocessing lexeme). | |
#define | ML99_seqGet(i) ML99_PRIV_CAT(ML99_PRIV_seqGet_, i) |
Expands to a metafunction extracting the i -indexed element of seq . | |
#define | ML99_seqTail(seq) ML99_call(ML99_seqTail, seq) |
Extracts the tail of seq . | |
#define | ML99_seqForEach(f, seq) ML99_call(ML99_seqForEach, f, seq) |
Applies f to each element in seq . | |
#define | ML99_seqForEachI(f, seq) ML99_call(ML99_seqForEachI, f, seq) |
Applies f to each element in seq with an index. | |
#define | ML99_SEQ_IS_EMPTY(seq) ML99_PRIV_NOT(ML99_PRIV_CONTAINS_COMMA(ML99_PRIV_COMMA seq)) |
#define | ML99_SEQ_GET(i) ML99_PRIV_CAT(ML99_PRIV_SEQ_GET_, i) |
#define | ML99_SEQ_TAIL(seq) ML99_PRIV_TAIL(ML99_PRIV_COMMA seq) |
Sequences: (x)(y)(z)
.
A sequence is represented as (...) (...) ...
. For example, these are sequences:
(~, ~, ~)
(1)(2)(3)
(+, -, *, /)(123)(~)
Sequences can represent syntax like X(...) Y(...) Z(...)
, where X
, Y
, and Z
expand to a tuple, thereby forming a sequence. A perfect example is Interface99, which allows a user to define a software interface via a number of vfunc(...)
macro invocations:
With vfunc
being defined as follows (simplified):
#define ML99_seqForEach | ( | f, | |
seq | |||
) | ML99_call(ML99_seqForEach, f, seq) |
Applies f
to each element in seq
.
The result is ML99_appl(f, x1) ... ML99_appl(f, xN)
.
#define ML99_seqForEachI | ( | f, | |
seq | |||
) | ML99_call(ML99_seqForEachI, f, seq) |
Applies f
to each element in seq
with an index.
The result is ML99_appl2(f, 0, x1) ... ML99_appl2(f, N - 1, xN)
.
#define ML99_seqGet | ( | i | ) | ML99_PRIV_CAT(ML99_PRIV_seqGet_, i) |
Expands to a metafunction extracting the i
-indexed element of seq
.
i
can range from 0 to 7, inclusively.
#define ML99_seqIsEmpty | ( | seq | ) | ML99_call(ML99_seqIsEmpty, seq) |
True iff seq
contains no elements (which means an empty preprocessing lexeme).
#define ML99_seqTail | ( | seq | ) | ML99_call(ML99_seqTail, seq) |
Extracts the tail of seq
.
seq
must contain at least one element. If seq
contains only one element, the result is ML99_empty()
.