Metalang99 1.13.3
Full-blown preprocessor metaprogramming
seq.h File Reference

Sequences: (x)(y)(z). More...

This graph shows which files directly or indirectly include this file:

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). More...
 
#define ML99_seqGet(i)   ML99_PRIV_CAT(ML99_PRIV_seqGet_, i)
 Expands to a metafunction extracting the i -indexed element of seq. More...
 
#define ML99_seqTail(seq)   ML99_call(ML99_seqTail, seq)
 Extracts the tail of seq. More...
 
#define ML99_seqForEach(f, seq)   ML99_call(ML99_seqForEach, f, seq)
 Applies f to each element in seq. More...
 
#define ML99_seqForEachI(f, seq)   ML99_call(ML99_seqForEachI, f, seq)
 Applies f to each element in seq with an index. More...
 
#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)
 

Detailed Description

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.

Macro Definition Documentation

◆ ML99_seqForEach

#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).

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)))
#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition: lang.h:145
Sequences: (x)(y)(z).
#define ML99_seqForEach(f, seq)
Applies f to each element in seq.
Definition: seq.h:110

◆ ML99_seqForEachI

#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).

#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)))
#define ML99_seqForEachI(f, seq)
Applies f to each element in seq with an index.
Definition: seq.h:127

◆ ML99_seqGet

#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.

Examples

#include <metalang99/seq.h>
// 2
ML99_seqGet(1)(v((1)(2)(3)))
#define ML99_seqGet(i)
Expands to a metafunction extracting the i -indexed element of seq.
Definition: seq.h:74

◆ ML99_seqIsEmpty

#define ML99_seqIsEmpty (   seq)    ML99_call(ML99_seqIsEmpty, seq)

True iff seq contains no elements (which means an empty preprocessing lexeme).

Examples

#include <metalang99/seq.h>
// 1
// 0
ML99_seqIsEmpty(v((~)(~)(~)))
#define ML99_seqIsEmpty(seq)
True iff seq contains no elements (which means an empty preprocessing lexeme).
Definition: seq.h:58

◆ ML99_seqTail

#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().

Examples

#include <metalang99/seq.h>
// (2)(3)
ML99_seqTail(v((1)(2)(3)))
#define ML99_seqTail(seq)
Extracts the tail of seq.
Definition: seq.h:91