Metalang99 1.13.3
Full-blown preprocessor metaprogramming
|
Cons-lists. More...
Go to the source code of this file.
Macros | |
#define | ML99_cons(x, xs) ML99_call(ML99_cons, x, xs) |
Prepends x to xs . More... | |
#define | ML99_nil(...) ML99_callUneval(ML99_nil, ) |
The empty list. | |
#define | ML99_isCons(list) ML99_call(ML99_isCons, list) |
Checks list for non-emptiness. More... | |
#define | ML99_isNil(list) ML99_call(ML99_isNil, list) |
Checks list for emptiness. More... | |
#define | ML99_listHead(list) ML99_call(ML99_listHead, list) |
Extracts the head from the non-empty list list . More... | |
#define | ML99_listTail(list) ML99_call(ML99_listTail, list) |
Extracts the tail from the non-empty list list . More... | |
#define | ML99_listLast(list) ML99_call(ML99_listLast, list) |
Extracts the last element from the non-empty list list . More... | |
#define | ML99_listInit(list) ML99_call(ML99_listInit, list) |
Extracts all the elements of the non-empty list list except the last one. More... | |
#define | ML99_list(...) ML99_call(ML99_list, __VA_ARGS__) |
Constructs a list from its arguments. More... | |
#define | ML99_listFromTuples(f, ...) ML99_call(ML99_listFromTuples, f, __VA_ARGS__) |
Constructs a list from comma-separated tuples. More... | |
#define | ML99_listFromSeq(seq) ML99_call(ML99_listFromSeq, seq) |
Constructs a list from the sequence seq . More... | |
#define | ML99_listLen(list) ML99_call(ML99_listLen, list) |
Computes the length of list . More... | |
#define | ML99_LIST_EVAL(...) ML99_EVAL(ML99_call(ML99_listUnwrap, __VA_ARGS__)) |
Evaluates a metaprogram that reduces to a list, then unwraps it. More... | |
#define | ML99_LIST_EVAL_COMMA_SEP(...) ML99_EVAL(ML99_call(ML99_listUnwrapCommaSep, __VA_ARGS__)) |
The same as ML99_LIST_EVAL but intersperses a comma between list items. More... | |
#define | ML99_listAppend(list, other) ML99_call(ML99_listAppend, list, other) |
Appends the list other to list . More... | |
#define | ML99_listAppendItem(item, list) ML99_call(ML99_listAppendItem, item, list) |
Appends the item item to list . More... | |
#define | ML99_listUnwrap(list) ML99_call(ML99_listUnwrap, list) |
Places all the items in list as-is. More... | |
#define | ML99_listUnwrapCommaSep(list) ML99_call(ML99_listUnwrapCommaSep, list) |
Places all the items in list as-is, separated by commas. More... | |
#define | ML99_listReverse(list) ML99_call(ML99_listReverse, list) |
Reverses the order of items in list . More... | |
#define | ML99_listGet(i, list) ML99_call(ML99_listGet, i, list) |
Extracts the i -indexed element. More... | |
#define | ML99_listFoldr(f, init, list) ML99_call(ML99_listFoldr, f, init, list) |
A right-associative fold over list . More... | |
#define | ML99_listFoldl(f, init, list) ML99_call(ML99_listFoldl, f, init, list) |
A left-associative fold over list . More... | |
#define | ML99_listFoldl1(f, list) ML99_call(ML99_listFoldl1, f, list) |
The same as ML99_listFoldl but treats the first element of list as the initial value. More... | |
#define | ML99_listIntersperse(item, list) ML99_call(ML99_listIntersperse, item, list) |
Intersperses item between the items in list . More... | |
#define | ML99_listPrependToAll(item, list) ML99_call(ML99_listPrependToAll, item, list) |
Prepends item to all items in list . More... | |
#define | ML99_listMap(f, list) ML99_call(ML99_listMap, f, list) |
Maps all the elements in list with f . More... | |
#define | ML99_listMapI(f, list) ML99_call(ML99_listMapI, f, list) |
The same as ML99_listMap but provides an index of an element to f . More... | |
#define | ML99_listMapInPlace(f, list) ML99_call(ML99_listMapInPlace, f, list) |
A more efficient version of ML99_listUnwrap(ML99_listMap(f, list)) . More... | |
#define | ML99_listMapInPlaceI(f, list) ML99_call(ML99_listMapInPlaceI, f, list) |
A more efficient version of ML99_listUnwrap(ML99_listMapI(f, list)) . More... | |
#define | ML99_listFor(list, f) ML99_call(ML99_listFor, list, f) |
The same as ML99_listMap but with the reversed order of arguments. More... | |
#define | ML99_listMapInitLast(f_init, f_last, list) ML99_call(ML99_listMapInitLast, f_init, f_last, list) |
Maps the initial elements of the non-empty list list with f_init and the last element with f_last . More... | |
#define | ML99_listForInitLast(list, f_init, f_last) ML99_call(ML99_listForInitLast, list, f_init, f_last) |
The same as ML99_listMapInitLast but accepts list as the first parameter. More... | |
#define | ML99_listFilter(f, list) ML99_call(ML99_listFilter, f, list) |
Filters list with f . More... | |
#define | ML99_listFilterMap(f, list) ML99_call(ML99_listFilterMap, f, list) |
A combination of ML99_listFilter and ML99_listMap. More... | |
#define | ML99_listEq(cmp, list, other) ML99_call(ML99_listEq, cmp, list, other) |
Tests list and other for equality. More... | |
#define | ML99_listContains(cmp, item, list) ML99_call(ML99_listContains, cmp, item, list) |
Checks whether item resides in list . More... | |
#define | ML99_listTake(n, list) ML99_call(ML99_listTake, n, list) |
Extracts the prefix of list of the length n . More... | |
#define | ML99_listTakeWhile(f, list) ML99_call(ML99_listTakeWhile, f, list) |
Extracts the items from list as long as f evaluates to ML99_true() . More... | |
#define | ML99_listDrop(n, list) ML99_call(ML99_listDrop, n, list) |
Removes the prefix of list of the length n . More... | |
#define | ML99_listDropWhile(f, list) ML99_call(ML99_listDropWhile, f, list) |
Removes the items from list as long as f evaluates to ML99_true() . More... | |
#define | ML99_listZip(list, other) ML99_call(ML99_listZip, list, other) |
Computes a list of two-place tuples of the corresponding items from list and other . More... | |
#define | ML99_listUnzip(list) ML99_call(ML99_listUnzip, list) |
Transforms a list of two-place tuples into a tuple of a list of the first components and a list of the second components. More... | |
#define | ML99_listReplicate(n, item) ML99_call(ML99_listReplicate, n, item) |
Computes a list of length n with each element item . More... | |
#define | ML99_listPartition(f, list) ML99_call(ML99_listPartition, f, list) |
Returns a two-place tuple of lists: those items of list the do and do not satisfy the predicate f , respectively. More... | |
#define | ML99_listAppl(f, list) ML99_call(ML99_listAppl, f, list) |
Applies all the items in list to f . More... | |
#define | ML99_CONS(x, xs) ML99_CHOICE(cons, x, xs) |
#define | ML99_NIL(...) ML99_CHOICE(nil, ~) |
#define | ML99_IS_CONS(list) ML99_NOT(ML99_IS_NIL(list)) |
#define | ML99_IS_NIL(list) ML99_PRIV_IS_NIL(list) |
Cons-lists.
#define ML99_cons | ( | x, | |
xs | |||
) | ML99_call(ML99_cons, x, xs) |
Prepends x
to xs
.
#define ML99_isCons | ( | list | ) | ML99_call(ML99_isCons, list) |
#define ML99_isNil | ( | list | ) | ML99_call(ML99_isNil, list) |
#define ML99_list | ( | ... | ) | ML99_call(ML99_list, __VA_ARGS__) |
Constructs a list from its arguments.
At most 63 arguments are acceptable.
#define ML99_LIST_EVAL | ( | ... | ) | ML99_EVAL(ML99_call(ML99_listUnwrap, __VA_ARGS__)) |
Evaluates a metaprogram that reduces to a list, then unwraps it.
It behaves the same as the composition of ML99_EVAL and ML99_listUnwrap.
#define ML99_LIST_EVAL_COMMA_SEP | ( | ... | ) | ML99_EVAL(ML99_call(ML99_listUnwrapCommaSep, __VA_ARGS__)) |
The same as ML99_LIST_EVAL but intersperses a comma between list items.
#define ML99_listAppend | ( | list, | |
other | |||
) | ML99_call(ML99_listAppend, list, other) |
Appends the list other
to list
.
#define ML99_listAppendItem | ( | item, | |
list | |||
) | ML99_call(ML99_listAppendItem, item, list) |
Appends the item item
to list
.
#define ML99_listAppl | ( | f, | |
list | |||
) | ML99_call(ML99_listAppl, f, list) |
Applies all the items in list
to f
.
If the list is empty, results in f
as-is.
#define ML99_listContains | ( | cmp, | |
item, | |||
list | |||
) | ML99_call(ML99_listContains, cmp, item, list) |
Checks whether item
resides in list
.
#define ML99_listDrop | ( | n, | |
list | |||
) | ML99_call(ML99_listDrop, n, list) |
Removes the prefix of list
of the length n
.
If n
is greater than the length of list
, ML99_nil()
is returned.
#define ML99_listDropWhile | ( | f, | |
list | |||
) | ML99_call(ML99_listDropWhile, f, list) |
Removes the items from list
as long as f
evaluates to ML99_true()
.
#define ML99_listEq | ( | cmp, | |
list, | |||
other | |||
) | ML99_call(ML99_listEq, cmp, list, other) |
Tests list
and other
for equality.
#define ML99_listFilter | ( | f, | |
list | |||
) | ML99_call(ML99_listFilter, f, list) |
#define ML99_listFilterMap | ( | f, | |
list | |||
) | ML99_call(ML99_listFilterMap, f, list) |
A combination of ML99_listFilter and ML99_listMap.
It builds a new list by applying f
to each element in list:
if f
yields ML99_just(x)
, x
is passed to the new list, otherwise (ML99_nothing()
), the value is neglected.
#define ML99_listFoldl | ( | f, | |
init, | |||
list | |||
) | ML99_call(ML99_listFoldl, f, init, list) |
A left-associative fold over list
.
#define ML99_listFoldl1 | ( | f, | |
list | |||
) | ML99_call(ML99_listFoldl1, f, list) |
The same as ML99_listFoldl but treats the first element of list
as the initial value.
#define ML99_listFoldr | ( | f, | |
init, | |||
list | |||
) | ML99_call(ML99_listFoldr, f, init, list) |
A right-associative fold over list
.
#define ML99_listFor | ( | list, | |
f | |||
) | ML99_call(ML99_listFor, list, f) |
The same as ML99_listMap but with the reversed order of arguments.
#define ML99_listForInitLast | ( | list, | |
f_init, | |||
f_last | |||
) | ML99_call(ML99_listForInitLast, list, f_init, f_last) |
The same as ML99_listMapInitLast but accepts list
as the first parameter.
#define ML99_listFromSeq | ( | seq | ) | ML99_call(ML99_listFromSeq, seq) |
Constructs a list from the sequence seq
.
#define ML99_listFromTuples | ( | f, | |
... | |||
) | ML99_call(ML99_listFromTuples, f, __VA_ARGS__) |
Constructs a list from comma-separated tuples.
It sequentially applies f
to each untupled argument, thus forming the resulting list. If some argument is not a tuple, a fatal error is emitted.
The result is ML99_list(ML99_appl(f, ML99_untuple(x1)), ..., ML99_appl(f, ML99_untuple(xN)))
.
Each variadic argument inherits all the preconditions of ML99_isUntuple.
#define ML99_listGet | ( | i, | |
list | |||
) | ML99_call(ML99_listGet, i, list) |
#define ML99_listHead | ( | list | ) | ML99_call(ML99_listHead, list) |
Extracts the head from the non-empty list list
.
#define ML99_listInit | ( | list | ) | ML99_call(ML99_listInit, list) |
Extracts all the elements of the non-empty list list
except the last one.
#define ML99_listIntersperse | ( | item, | |
list | |||
) | ML99_call(ML99_listIntersperse, item, list) |
Intersperses item
between the items in list
.
#define ML99_listLast | ( | list | ) | ML99_call(ML99_listLast, list) |
Extracts the last element from the non-empty list list
.
#define ML99_listLen | ( | list | ) | ML99_call(ML99_listLen, list) |
#define ML99_listMap | ( | f, | |
list | |||
) | ML99_call(ML99_listMap, f, list) |
Maps all the elements in list
with f
.
#define ML99_listMapI | ( | f, | |
list | |||
) | ML99_call(ML99_listMapI, f, list) |
The same as ML99_listMap but provides an index of an element to f
.
#define ML99_listMapInitLast | ( | f_init, | |
f_last, | |||
list | |||
) | ML99_call(ML99_listMapInitLast, f_init, f_last, list) |
Maps the initial elements of the non-empty list list
with f_init
and the last element with f_last
.
#define ML99_listMapInPlace | ( | f, | |
list | |||
) | ML99_call(ML99_listMapInPlace, f, list) |
A more efficient version of ML99_listUnwrap(ML99_listMap(f, list))
.
f
can evaluate to many terms. #define ML99_listMapInPlaceI | ( | f, | |
list | |||
) | ML99_call(ML99_listMapInPlaceI, f, list) |
A more efficient version of ML99_listUnwrap(ML99_listMapI(f, list))
.
f
can evaluate to many terms. #define ML99_listPartition | ( | f, | |
list | |||
) | ML99_call(ML99_listPartition, f, list) |
Returns a two-place tuple of lists: those items of list
the do and do not satisfy the predicate f
, respectively.
#define ML99_listPrependToAll | ( | item, | |
list | |||
) | ML99_call(ML99_listPrependToAll, item, list) |
Prepends item
to all items in list
.
#define ML99_listReplicate | ( | n, | |
item | |||
) | ML99_call(ML99_listReplicate, n, item) |
Computes a list of length n
with each element item
.
#define ML99_listReverse | ( | list | ) | ML99_call(ML99_listReverse, list) |
Reverses the order of items in list
.
#define ML99_listTail | ( | list | ) | ML99_call(ML99_listTail, list) |
Extracts the tail from the non-empty list list
.
#define ML99_listTake | ( | n, | |
list | |||
) | ML99_call(ML99_listTake, n, list) |
Extracts the prefix of list
of the length n
.
If n
is greater than the length of list
, the whole list
is returned.
#define ML99_listTakeWhile | ( | f, | |
list | |||
) | ML99_call(ML99_listTakeWhile, f, list) |
Extracts the items from list
as long as f
evaluates to ML99_true()
.
#define ML99_listUnwrap | ( | list | ) | ML99_call(ML99_listUnwrap, list) |
Places all the items in list
as-is.
#define ML99_listUnwrapCommaSep | ( | list | ) | ML99_call(ML99_listUnwrapCommaSep, list) |
Places all the items in list
as-is, separated by commas.
#define ML99_listUnzip | ( | list | ) | ML99_call(ML99_listUnzip, list) |
Transforms a list of two-place tuples into a tuple of a list of the first components and a list of the second components.
#define ML99_listZip | ( | list, | |
other | |||
) | ML99_call(ML99_listZip, list, other) |
Computes a list of two-place tuples of the corresponding items from list
and other
.