seq.h¶
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:
#define Shape_IFACE \
vfunc( int, perim, const VSelf) \
vfunc(void, scale, VSelf, int factor)
interface(Shape);
With vfunc
being defined as follows (simplified):
#define vfunc(ret_ty, name, ...) (ret_ty, name, __VA_ARGS__)
Note
Sequences are more time and space-efficient than lists, but export less functionality; if a needed function is missed, invoking ML99_listFromSeq and then manipulating with the resulting Cons-list might be helpful.
Defines
-
ML99_seqIsEmpty(seq)¶
True iff
seq
contains no elements (which means an empty preprocessing lexeme).Examples
#include <metalang99/seq.h> // 1 ML99_seqIsEmpty(v()) // 0 ML99_seqIsEmpty(v((~)(~)(~)))
-
ML99_seqGet(i)¶
Expands to a metafunction extracting the
i
-indexed element ofseq
.i
can range from 0 to 7, inclusively.Examples
#include <metalang99/seq.h> // 2 ML99_seqGet(1)(v((1)(2)(3)))
-
ML99_seqTail(seq)¶
Extracts the tail of
seq
.seq
must contain at least one element. Ifseq
contains only one element, the result isML99_empty()
.Examples
#include <metalang99/seq.h> // (2)(3) ML99_seqTail(v((1)(2)(3)))
-
ML99_seqForEach(f, seq)¶
Applies
f
to each element inseq
.The result is
ML99_appl(f, x1) ... ML99_appl(f, xN)
.Examples
#include <metalang99/seq.h> #define F_IMPL(x) v(@x) #define F_ARITY 1 // @x @y @z ML99_seqForEach(v(F), v((x)(y)(z)))
-
ML99_seqForEachI(f, seq)¶
Applies
f
to each element inseq
with an index.The result is
ML99_appl2(f, 0, x1) ... ML99_appl2(f, N - 1, xN)
.#include <metalang99/seq.h> #define F_IMPL(i, x) v(@x##i) #define F_ARITY 2 // @x0 @y1 @z2 ML99_seqForEachI(v(F), v((x)(y)(z)))
-
ML99_SEQ_IS_EMPTY(seq)¶
-
ML99_SEQ_GET(i)¶
-
ML99_SEQ_TAIL(seq)¶