Loading...
Searching...
No Matches
list.h
Go to the documentation of this file.
#ifndef ML99_LIST_H
#define ML99_LIST_H
#include <metalang99/priv/bool.h>
#include <metalang99/priv/util.h>
#include <metalang99/bool.h>
#include <metalang99/choice.h>
#include <metalang99/nat.h>
#include <metalang99/seq.h>
#include <metalang99/util.h>
#include <metalang99/variadics.h>
#define ML99_cons(x, xs) ML99_call(ML99_cons, x, xs)
#define ML99_nil(...) ML99_callUneval(ML99_nil, )
#define ML99_isCons(list) ML99_call(ML99_isCons, list)
#define ML99_isNil(list) ML99_call(ML99_isNil, list)
#define ML99_listHead(list) ML99_call(ML99_listHead, list)
#define ML99_listTail(list) ML99_call(ML99_listTail, list)
#define ML99_listLast(list) ML99_call(ML99_listLast, list)
#define ML99_listInit(list) ML99_call(ML99_listInit, list)
#define ML99_list(...) ML99_call(ML99_list, __VA_ARGS__)
#define ML99_listFromTuples(f, ...) ML99_call(ML99_listFromTuples, f, __VA_ARGS__)
#define ML99_listFromSeq(seq) ML99_call(ML99_listFromSeq, seq)
#define ML99_listLen(list) ML99_call(ML99_listLen, list)
#define ML99_LIST_EVAL(...) ML99_EVAL(ML99_call(ML99_listUnwrap, __VA_ARGS__))
#define ML99_LIST_EVAL_COMMA_SEP(...) ML99_EVAL(ML99_call(ML99_listUnwrapCommaSep, __VA_ARGS__))
#define ML99_listAppend(list, other) ML99_call(ML99_listAppend, list, other)
#define ML99_listAppendItem(item, list) ML99_call(ML99_listAppendItem, item, list)
#define ML99_listUnwrap(list) ML99_call(ML99_listUnwrap, list)
#define ML99_listUnwrapCommaSep(list) ML99_call(ML99_listUnwrapCommaSep, list)
#define ML99_listReverse(list) ML99_call(ML99_listReverse, list)
#define ML99_listGet(i, list) ML99_call(ML99_listGet, i, list)
#define ML99_listFoldr(f, init, list) ML99_call(ML99_listFoldr, f, init, list)
#define ML99_listFoldl(f, init, list) ML99_call(ML99_listFoldl, f, init, list)
#define ML99_listFoldl1(f, list) ML99_call(ML99_listFoldl1, f, list)
#define ML99_listIntersperse(item, list) ML99_call(ML99_listIntersperse, item, list)
#define ML99_listPrependToAll(item, list) ML99_call(ML99_listPrependToAll, item, list)
#define ML99_listMap(f, list) ML99_call(ML99_listMap, f, list)
#define ML99_listMapI(f, list) ML99_call(ML99_listMapI, f, list)
#define ML99_listMapInPlace(f, list) ML99_call(ML99_listMapInPlace, f, list)
#define ML99_listMapInPlaceI(f, list) ML99_call(ML99_listMapInPlaceI, f, list)
#define ML99_listFor(list, f) ML99_call(ML99_listFor, list, f)
#define ML99_listMapInitLast(f_init, f_last, list) \
ML99_call(ML99_listMapInitLast, f_init, f_last, list)
#define ML99_listForInitLast(list, f_init, f_last) \
ML99_call(ML99_listForInitLast, list, f_init, f_last)
#define ML99_listFilter(f, list) ML99_call(ML99_listFilter, f, list)
#define ML99_listFilterMap(f, list) ML99_call(ML99_listFilterMap, f, list)
#define ML99_listEq(cmp, list, other) ML99_call(ML99_listEq, cmp, list, other)
#define ML99_listContains(cmp, item, list) ML99_call(ML99_listContains, cmp, item, list)
#define ML99_listTake(n, list) ML99_call(ML99_listTake, n, list)
#define ML99_listTakeWhile(f, list) ML99_call(ML99_listTakeWhile, f, list)
#define ML99_listDrop(n, list) ML99_call(ML99_listDrop, n, list)
#define ML99_listDropWhile(f, list) ML99_call(ML99_listDropWhile, f, list)
#define ML99_listZip(list, other) ML99_call(ML99_listZip, list, other)
#define ML99_listUnzip(list) ML99_call(ML99_listUnzip, list)
#define ML99_listReplicate(n, item) ML99_call(ML99_listReplicate, n, item)
#define ML99_listPartition(f, list) ML99_call(ML99_listPartition, f, list)
#define ML99_listAppl(f, list) ML99_call(ML99_listAppl, f, list)
#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)
#ifndef DOXYGEN_IGNORE
#define ML99_cons_IMPL(x, xs) v(ML99_CONS(x, xs))
#define ML99_nil_IMPL(...) v(ML99_NIL())
#define ML99_isCons_IMPL(list) v(ML99_IS_CONS(list))
#define ML99_isNil_IMPL(list) v(ML99_IS_NIL(list))
#define ML99_listHead_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listHead_)
#define ML99_PRIV_listHead_nil_IMPL(_) ML99_PRIV_EMPTY_LIST_ERROR(listHead)
#define ML99_PRIV_listHead_cons_IMPL(x, _xs) v(x)
#define ML99_listTail_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listTail_)
#define ML99_PRIV_listTail_nil_IMPL(_) ML99_PRIV_EMPTY_LIST_ERROR(listTail)
#define ML99_PRIV_listTail_cons_IMPL(_x, xs) v(xs)
#define ML99_listLast_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listLast_)
#define ML99_PRIV_listLast_nil_IMPL(_) ML99_PRIV_EMPTY_LIST_ERROR(listLast)
#define ML99_PRIV_listLast_cons_IMPL(x, xs) \
ML99_PRIV_IF(ML99_IS_NIL(xs), v(x), ML99_listLast_IMPL(xs))
#define ML99_listInit_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listInit_)
#define ML99_PRIV_listInit_nil_IMPL(_) ML99_PRIV_EMPTY_LIST_ERROR(listInit)
#define ML99_PRIV_listInit_cons_IMPL(x, xs) \
ML99_PRIV_IF(ML99_IS_NIL(xs), v(ML99_NIL()), ML99_cons(v(x), ML99_listInit_IMPL(xs)))
// ML99_list_IMPL {
#define ML99_list_IMPL(...) \
ML99_PRIV_listProgress_IMPL(ML99_VARIADICS_COUNT(__VA_ARGS__), __VA_ARGS__, ~)
// Last 4 recursion steps unrolled.
#define ML99_PRIV_listProgress_IMPL(count, ...) \
ML99_PRIV_IF( \
ML99_NAT_EQ(count, 4), \
ML99_PRIV_listDone_4, \
ML99_PRIV_IF( \
ML99_NAT_EQ(count, 3), \
ML99_PRIV_listDone_3, \
ML99_PRIV_IF( \
ML99_NAT_EQ(count, 2), \
ML99_PRIV_listDone_2, \
ML99_PRIV_IF( \
ML99_NAT_EQ(count, 1), \
ML99_PRIV_listDone_1, \
ML99_PRIV_IF( \
ML99_NAT_EQ(count, 0), \
ML99_PRIV_listDone_0, \
ML99_PRIV_listProgressAux))))) \
(count, __VA_ARGS__)
#define ML99_PRIV_listProgressAux(count, x, ...) \
ML99_cons(v(x), ML99_callUneval(ML99_PRIV_listProgress, ML99_DEC(count), __VA_ARGS__))
#define ML99_PRIV_listDone_0(_count, _) v(ML99_NIL())
#define ML99_PRIV_listDone_1(_count, a, _) v(ML99_CONS(a, ML99_NIL()))
#define ML99_PRIV_listDone_2(_count, a, b, _) v(ML99_CONS(a, ML99_CONS(b, ML99_NIL())))
#define ML99_PRIV_listDone_3(_count, a, b, c, _) \
v(ML99_CONS(a, ML99_CONS(b, ML99_CONS(c, ML99_NIL()))))
#define ML99_PRIV_listDone_4(_count, a, b, c, d, _) \
v(ML99_CONS(a, ML99_CONS(b, ML99_CONS(c, ML99_CONS(d, ML99_NIL())))))
// } (ML99_list_IMPL)
// ML99_listFromTuples_IMPL {
#define ML99_listFromTuples_IMPL(f, ...) ML99_PRIV_listFromTuplesAux_IMPL(f, __VA_ARGS__, ~)
#define ML99_PRIV_listFromTuplesAux_IMPL(f, x, ...) \
ML99_PRIV_CAT(ML99_PRIV_listFromTuples_, ML99_IS_UNTUPLE(x))(f, x, __VA_ARGS__)
#define ML99_PRIV_listFromTuples_1(_f, x, ...) ML99_PRIV_NOT_TUPLE_ERROR(x)
#define ML99_PRIV_listFromTuples_0(f, x, ...) \
ML99_cons( \
ML99_appl_IMPL(f, ML99_UNTUPLE(x)), \
ML99_PRIV_IF( \
ML99_VARIADICS_IS_SINGLE(__VA_ARGS__), \
v(ML99_NIL()), \
ML99_callUneval(ML99_PRIV_listFromTuplesAux, f, __VA_ARGS__)))
// } (ML99_listFromTuples_IMPL)
#define ML99_listFromSeq_IMPL(seq) \
ML99_PRIV_CAT(ML99_PRIV_listFromSeq_, ML99_SEQ_IS_EMPTY(seq))(seq)
#define ML99_PRIV_listFromSeq_1 ML99_nil_IMPL
#define ML99_PRIV_listFromSeq_0(seq) \
ML99_cons(v(ML99_SEQ_GET(0)(seq)), ML99_callUneval(ML99_listFromSeq, ML99_SEQ_TAIL(seq)))
#define ML99_listLen_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listLen_)
#define ML99_PRIV_listLen_nil_IMPL(_) v(0)
#define ML99_PRIV_listLen_cons_IMPL(_x, xs) ML99_inc(ML99_listLen_IMPL(xs))
#define ML99_listAppend_IMPL(list, other) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listAppend_, other)
#define ML99_PRIV_listAppend_nil_IMPL(_, other) v(other)
#define ML99_PRIV_listAppend_cons_IMPL(x, xs, other) \
ML99_cons(v(x), ML99_listAppend_IMPL(xs, other))
#define ML99_listAppendItem_IMPL(item, list) ML99_listAppend_IMPL(list, ML99_CONS(item, ML99_NIL()))
#define ML99_listUnwrap_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listUnwrap_)
#define ML99_PRIV_listUnwrap_nil_IMPL ML99_empty_IMPL
#define ML99_PRIV_listUnwrap_cons_IMPL(x, xs) ML99_TERMS(v(x), ML99_listUnwrap_IMPL(xs))
#define ML99_listReverse_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listReverse_)
#define ML99_PRIV_listReverse_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listReverse_cons_IMPL(x, xs) ML99_listAppendItem(v(x), ML99_listReverse_IMPL(xs))
#define ML99_listGet_IMPL(i, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listGet_, i)
#define ML99_PRIV_listGet_nil_IMPL(_, i) ML99_PRIV_EMPTY_LIST_ERROR(ML99_listGet)
#define ML99_PRIV_listGet_cons_IMPL(x, xs, i) \
ML99_PRIV_IF(ML99_NAT_EQ(i, 0), v(x), ML99_listGet_IMPL(ML99_DEC(i), xs))
#define ML99_listFoldr_IMPL(f, init, list) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listFoldr_, f, init)
#define ML99_PRIV_listFoldr_nil_IMPL(_, _f, acc) v(acc)
#define ML99_PRIV_listFoldr_cons_IMPL(x, xs, f, acc) \
ML99_call(ML99_appl2, v(f, x), ML99_listFoldr_IMPL(f, acc, xs))
#define ML99_listFoldl_IMPL(f, init, list) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listFoldl_, f, init)
#define ML99_PRIV_listFoldl_nil_IMPL(_, _f, acc) v(acc)
#define ML99_PRIV_listFoldl_cons_IMPL(x, xs, f, acc) \
ML99_listFoldl(v(f), ML99_appl2_IMPL(f, acc, x), v(xs))
#define ML99_listFoldl1_IMPL(f, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listFoldl1_, f)
#define ML99_PRIV_listFoldl1_nil_IMPL(_, _f) ML99_PRIV_EMPTY_LIST_ERROR(ML99_listFoldl1)
#define ML99_PRIV_listFoldl1_cons_IMPL(x, xs, f) ML99_listFoldl_IMPL(f, x, xs)
#define ML99_listIntersperse_IMPL(item, list) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listIntersperse_, item)
#define ML99_PRIV_listIntersperse_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listIntersperse_cons_IMPL(x, xs, item) \
ML99_cons(v(x), ML99_listPrependToAll_IMPL(item, xs))
#define ML99_listPrependToAll_IMPL(item, list) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listPrependToAll_, item)
#define ML99_PRIV_listPrependToAll_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listPrependToAll_cons_IMPL(x, xs, item) \
ML99_cons(v(item), ML99_cons(v(x), ML99_listPrependToAll_IMPL(item, xs)))
#define ML99_listMap_IMPL(f, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listMap_, f)
#define ML99_PRIV_listMap_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listMap_cons_IMPL(x, xs, f) \
ML99_cons(ML99_appl_IMPL(f, x), ML99_listMap_IMPL(f, xs))
#define ML99_listMapI_IMPL(f, list) ML99_PRIV_listMapIAux_IMPL(f, list, 0)
#define ML99_PRIV_listMapIAux_IMPL(f, list, i) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listMapI_, f, i)
#define ML99_PRIV_listMapI_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listMapI_cons_IMPL(x, xs, f, i) \
ML99_cons(ML99_appl2_IMPL(f, x, i), ML99_PRIV_listMapIAux_IMPL(f, xs, ML99_INC(i)))
#define ML99_listMapInPlace_IMPL(f, list) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listMapInPlace_, f)
#define ML99_PRIV_listMapInPlace_nil_IMPL ML99_empty_IMPL
#define ML99_PRIV_listMapInPlace_cons_IMPL(x, xs, f) \
ML99_TERMS(ML99_appl_IMPL(f, x), ML99_listMapInPlace_IMPL(f, xs))
#define ML99_listMapInPlaceI_IMPL(f, list) ML99_PRIV_listMapInPlaceIAux_IMPL(f, list, 0)
#define ML99_PRIV_listMapInPlaceIAux_IMPL(f, list, i) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listMapInPlaceI_, f, i)
#define ML99_PRIV_listMapInPlaceI_nil_IMPL ML99_empty_IMPL
#define ML99_PRIV_listMapInPlaceI_cons_IMPL(x, xs, f, i) \
ML99_TERMS(ML99_appl2_IMPL(f, x, i), ML99_PRIV_listMapInPlaceIAux_IMPL(f, xs, ML99_INC(i)))
#define ML99_listFor_IMPL(list, f) ML99_listMap_IMPL(f, list)
#define ML99_listMapInitLast_IMPL(f_init, f_last, list) \
ML99_listAppendItem( \
ML99_appl(v(f_last), ML99_listLast_IMPL(list)), \
ML99_listMap(v(f_init), ML99_listInit_IMPL(list)))
#define ML99_listForInitLast_IMPL(list, f_init, f_last) \
ML99_listMapInitLast_IMPL(f_init, f_last, list)
// ML99_listFilter_IMPL {
#define ML99_listFilter_IMPL(f, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listFilter_, f)
#define ML99_PRIV_listFilter_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listFilter_cons_IMPL(x, xs, f) \
ML99_call( \
ML99_boolMatchWithArgs, \
ML99_appl_IMPL(f, x), \
v(ML99_PRIV_listFilter_cons_, x), \
ML99_listFilter_IMPL(f, xs))
#define ML99_PRIV_listFilter_cons_1_IMPL(x, rest) v(ML99_CONS(x, rest))
#define ML99_PRIV_listFilter_cons_0_IMPL(_x, rest) v(rest)
// } (ML99_listFilter_IMPL)
// ML99_listFilterMap_IMPL {
#define ML99_listFilterMap_IMPL(f, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listFilterMap_, f)
#define ML99_PRIV_listFilterMap_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listFilterMap_cons_IMPL(x, xs, f) \
ML99_call(ML99_matchWithArgs, ML99_appl_IMPL(f, x), v(ML99_PRIV_listFilterMap_cons_, f, xs))
#define ML99_PRIV_listFilterMap_cons_just_IMPL(y, f, xs) \
ML99_cons(v(y), ML99_listFilterMap_IMPL(f, xs))
#define ML99_PRIV_listFilterMap_cons_nothing_IMPL(_, f, xs) ML99_listFilterMap_IMPL(f, xs)
// } (ML99_listFilterMap_IMPL)
// ML99_listEq_IMPL {
#define ML99_listEq_IMPL(cmp, list, other) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listEq_, other, cmp)
#define ML99_PRIV_listEq_nil_IMPL(_, other, _cmp) v(ML99_IS_NIL(other))
#define ML99_PRIV_listEq_cons_IMPL(x, xs, other, cmp) \
ML99_matchWithArgs_IMPL(other, ML99_PRIV_listEq_cons_, x, xs, cmp)
#define ML99_PRIV_listEq_cons_nil_IMPL ML99_false_IMPL
#define ML99_PRIV_listEq_cons_cons_IMPL(other_x, other_xs, x, xs, cmp) \
ML99_call( \
ML99_call(ML99_if, ML99_appl2_IMPL(cmp, x, other_x), v(ML99_listEq, ML99_false)), \
v(cmp, xs, other_xs))
// } (ML99_listEq_IMPL)
#define ML99_listContains_IMPL(cmp, item, list) \
ML99_matchWithArgs_IMPL(list, ML99_PRIV_listContains_, item, cmp)
#define ML99_PRIV_listContains_nil_IMPL ML99_false_IMPL
#define ML99_PRIV_listContains_cons_IMPL(x, xs, item, cmp) \
ML99_call( \
ML99_call(ML99_if, ML99_appl2_IMPL(cmp, x, item), v(ML99_true, ML99_listContains)), \
v(cmp, item, xs))
#define ML99_listTake_IMPL(n, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listTake_, n)
#define ML99_PRIV_listTake_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listTake_cons_IMPL(x, xs, i) \
ML99_PRIV_IF( \
ML99_NAT_EQ(i, 0), \
v(ML99_NIL()), \
ML99_cons(v(x), ML99_listTake_IMPL(ML99_DEC(i), xs)))
// ML99_listTakeWhile_IMPL {
#define ML99_listTakeWhile_IMPL(f, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listTakeWhile_, f)
#define ML99_PRIV_listTakeWhile_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listTakeWhile_cons_IMPL(x, xs, f) \
ML99_call( \
ML99_boolMatchWithArgs, \
ML99_appl_IMPL(f, x), \
v(ML99_PRIV_listTakeWhile_cons_, x, xs, f))
#define ML99_PRIV_listTakeWhile_cons_1_IMPL(x, xs, f) \
ML99_cons(v(x), ML99_listTakeWhile_IMPL(f, xs))
#define ML99_PRIV_listTakeWhile_cons_0_IMPL ML99_nil_IMPL
// } (ML99_listTakeWhile_IMPL)
#define ML99_listDrop_IMPL(n, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listDrop_, n)
#define ML99_PRIV_listDrop_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listDrop_cons_IMPL(x, xs, i) \
ML99_PRIV_IF(ML99_NAT_EQ(i, 0), v(ML99_CONS(x, xs)), ML99_listDrop_IMPL(ML99_DEC(i), xs))
// ML99_listDropWhile_IMPL {
#define ML99_listDropWhile_IMPL(f, list) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listDropWhile_, f)
#define ML99_PRIV_listDropWhile_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listDropWhile_cons_IMPL(x, xs, f) \
ML99_call( \
ML99_boolMatchWithArgs, \
ML99_appl_IMPL(f, x), \
v(ML99_PRIV_listDropWhile_cons_, x, xs, f))
#define ML99_PRIV_listDropWhile_cons_0_IMPL(x, xs, _f) v(ML99_CONS(x, xs))
#define ML99_PRIV_listDropWhile_cons_1_IMPL(_x, xs, f) ML99_listDropWhile_IMPL(f, xs)
// } (ML99_listDropWhile_IMPL)
// ML99_listZip_IMPL {
#define ML99_listZip_IMPL(list, other) ML99_matchWithArgs_IMPL(list, ML99_PRIV_listZip_, other)
#define ML99_PRIV_listZip_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listZip_cons_IMPL(x, xs, other) \
ML99_matchWithArgs_IMPL(other, ML99_PRIV_listZip_cons_, x, xs)
#define ML99_PRIV_listZip_cons_nil_IMPL ML99_nil_IMPL
#define ML99_PRIV_listZip_cons_cons_IMPL(other_x, other_xs, x, xs) \
ML99_cons(v(ML99_TUPLE(x, other_x)), ML99_listZip_IMPL(xs, other_xs))
// } (ML99_listZip_IMPL)
// ML99_listUnzip_IMPL {
#define ML99_listUnzip_IMPL(list) ML99_match_IMPL(list, ML99_PRIV_listUnzip_)
#define ML99_PRIV_listUnzip_nil_IMPL(_) v(ML99_TUPLE(ML99_NIL(), ML99_NIL()))
#define ML99_PRIV_listUnzip_cons_IMPL(x, xs) \
ML99_call(ML99_PRIV_listUnzipProgress, v(x), ML99_listUnzip_IMPL(xs))
#define ML99_PRIV_listUnzipProgress_IMPL(x, rest) \
v(ML99_TUPLE(ML99_PRIV_LIST_UNZIP_EXTEND(x, rest, 0), ML99_PRIV_LIST_UNZIP_EXTEND(x, rest, 1)))
#define ML99_PRIV_LIST_UNZIP_EXTEND(x, rest, i) \
ML99_CONS(ML99_TUPLE_GET(i)(x), ML99_TUPLE_GET(i)(rest))
// } (ML99_listUnzip_IMPL)
#define ML99_listReplicate_IMPL(n, item) \
ML99_natMatchWithArgs_IMPL(n, ML99_PRIV_listReplicate_, item)
#define ML99_PRIV_listReplicate_Z_IMPL ML99_nil_IMPL
#define ML99_PRIV_listReplicate_S_IMPL(n, item) ML99_cons(v(item), ML99_listReplicate_IMPL(n, item))
// ML99_listPartition_IMPL {
#define ML99_listPartition_IMPL(f, list) \
ML99_listFoldr( \
ML99_appl_IMPL(ML99_PRIV_listPartitionAux, f), \
v(ML99_TUPLE(ML99_NIL(), ML99_NIL())), \
v(list))
#define ML99_PRIV_listPartitionAux_IMPL(f, x, acc) \
ML99_call( \
ML99_boolMatchWithArgs, \
ML99_appl_IMPL(f, x), \
v(ML99_PRIV_listPartition_, x, ML99_UNTUPLE(acc)))
#define ML99_PRIV_listPartition_1_IMPL(x, fst, snd) v(ML99_TUPLE(ML99_CONS(x, fst), snd))
#define ML99_PRIV_listPartition_0_IMPL(x, fst, snd) v(ML99_TUPLE(fst, ML99_CONS(x, snd)))
// } (ML99_listPartition_IMPL)
#define ML99_listAppl_IMPL(f, list) ML99_listFoldl_IMPL(ML99_appl, f, list)
// ML99_listUnwrapCommaSep_IMPL {
#define ML99_listUnwrapCommaSep_IMPL(list) \
ML99_PRIV_IF( \
ML99_IS_NIL(list), \
v(ML99_EMPTY()), \
ML99_variadicsTail(ML99_PRIV_listUnwrapCommaSepAux_IMPL(list)))
#define ML99_PRIV_listUnwrapCommaSepAux_IMPL(xs) ML99_match_IMPL(xs, ML99_PRIV_listUnwrapCommaSep_)
#define ML99_PRIV_listUnwrapCommaSep_nil_IMPL ML99_empty_IMPL
#define ML99_PRIV_listUnwrapCommaSep_cons_IMPL(x, xs) \
ML99_TERMS(v(, x), ML99_PRIV_listUnwrapCommaSepAux_IMPL(xs))
// } (ML99_listUnwrapCommaSep_IMPL)
// clang-format off
#define ML99_PRIV_EMPTY_LIST_ERROR(f) ML99_fatal(ML99_##f, expected a non-empty list)
// clang-format on
#define ML99_PRIV_IS_NIL(list) ML99_DETECT_IDENT(ML99_PRIV_IS_NIL_, ML99_CHOICE_TAG(list))
#define ML99_PRIV_IS_NIL_nil ()
// Arity specifiers {
#define ML99_cons_ARITY 2
#define ML99_nil_ARITY 1
#define ML99_isCons_ARITY 1
#define ML99_isNil_ARITY 1
#define ML99_listHead_ARITY 1
#define ML99_listTail_ARITY 1
#define ML99_listLast_ARITY 1
#define ML99_listInit_ARITY 1
#define ML99_list_ARITY 1
#define ML99_listFromTuples_ARITY 2
#define ML99_listFromSeq_ARITY 1
#define ML99_listLen_ARITY 1
#define ML99_listAppend_ARITY 2
#define ML99_listAppendItem_ARITY 2
#define ML99_listUnwrap_ARITY 1
#define ML99_listUnwrapCommaSep_ARITY 1
#define ML99_listReverse_ARITY 1
#define ML99_listGet_ARITY 2
#define ML99_listFoldr_ARITY 3
#define ML99_listFoldl_ARITY 3
#define ML99_listFoldl1_ARITY 2
#define ML99_listIntersperse_ARITY 2
#define ML99_listPrependToAll_ARITY 2
#define ML99_listMap_ARITY 2
#define ML99_listMapI_ARITY 2
#define ML99_listMapInPlace_ARITY 2
#define ML99_listMapInPlaceI_ARITY 2
#define ML99_listFor_ARITY 2
#define ML99_listMapInitLast_ARITY 3
#define ML99_listForInitLast_ARITY 3
#define ML99_listFilter_ARITY 2
#define ML99_listFilterMap_ARITY 2
#define ML99_listEq_ARITY 3
#define ML99_listContains_ARITY 3
#define ML99_listTake_ARITY 2
#define ML99_listTakeWhile_ARITY 2
#define ML99_listDrop_ARITY 2
#define ML99_listDropWhile_ARITY 2
#define ML99_listZip_ARITY 2
#define ML99_listUnzip_ARITY 1
#define ML99_listReplicate_ARITY 2
#define ML99_listPartition_ARITY 2
#define ML99_listAppl_ARITY 2
#define ML99_PRIV_listPartitionAux_ARITY 3
// } (Arity specifiers)
#endif // DOXYGEN_IGNORE
#endif // ML99_LIST_H
bool.h
Boolean algebra.
choice.h
Choice types: (tag, ...).
nat.h
Natural numbers: [0; 255].
seq.h
Sequences: (x)(y)(z).
util.h
Utilitary stuff.
variadics.h
Variadic arguments: x, y, z.