Metalang99 1.13.5
Full-blown preprocessor metaprogramming
Loading...
Searching...
No Matches
list.h File Reference

Cons-lists. More...

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

Go to the source code of this file.

Macros

#define ML99_cons(x, xs)
 Prepends x to xs.
#define ML99_nil(...)
 The empty list.
#define ML99_isCons(list)
 Checks list for non-emptiness.
#define ML99_isNil(list)
 Checks list for emptiness.
#define ML99_listHead(list)
 Extracts the head from the non-empty list list.
#define ML99_listTail(list)
 Extracts the tail from the non-empty list list.
#define ML99_listLast(list)
 Extracts the last element from the non-empty list list.
#define ML99_listInit(list)
 Extracts all the elements of the non-empty list list except the last one.
#define ML99_list(...)
 Constructs a list from its arguments.
#define ML99_listFromTuples(f, ...)
 Constructs a list from comma-separated tuples.
#define ML99_listFromSeq(seq)
 Constructs a list from the sequence seq.
#define ML99_listLen(list)
 Computes the length of list.
#define ML99_LIST_EVAL(...)
 Evaluates a metaprogram that reduces to a list, then unwraps it.
#define ML99_LIST_EVAL_COMMA_SEP(...)
 The same as ML99_LIST_EVAL but intersperses a comma between list items.
#define ML99_listAppend(list, other)
 Appends the list other to list.
#define ML99_listAppendItem(item, list)
 Appends the item item to list.
#define ML99_listUnwrap(list)
 Places all the items in list as-is.
#define ML99_listUnwrapCommaSep(list)
 Places all the items in list as-is, separated by commas.
#define ML99_listReverse(list)
 Reverses the order of items in list.
#define ML99_listGet(i, list)
 Extracts the i -indexed element.
#define ML99_listFoldr(f, init, list)
 A right-associative fold over list.
#define ML99_listFoldl(f, init, list)
 A left-associative fold over list.
#define ML99_listFoldl1(f, list)
 The same as ML99_listFoldl but treats the first element of list as the initial value.
#define ML99_listIntersperse(item, list)
 Intersperses item between the items in list.
#define ML99_listPrependToAll(item, list)
 Prepends item to all items in list.
#define ML99_listMap(f, list)
 Maps all the elements in list with f.
#define ML99_listMapI(f, list)
 The same as ML99_listMap but provides an index of an element to f.
#define ML99_listMapInPlace(f, list)
 A more efficient version of ML99_listUnwrap(ML99_listMap(f, list)).
#define ML99_listMapInPlaceI(f, list)
 A more efficient version of ML99_listUnwrap(ML99_listMapI(f, list)).
#define ML99_listFor(list, f)
 The same as ML99_listMap but with the reversed order of arguments.
#define 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_listForInitLast(list, f_init, f_last)
 The same as ML99_listMapInitLast but accepts list as the first parameter.
#define ML99_listFilter(f, list)
 Filters list with f.
#define ML99_listFilterMap(f, list)
 A combination of ML99_listFilter and ML99_listMap.
#define ML99_listEq(cmp, list, other)
 Tests list and other for equality.
#define ML99_listContains(cmp, item, list)
 Checks whether item resides in list.
#define ML99_listTake(n, list)
 Extracts the prefix of list of the length n.
#define ML99_listTakeWhile(f, list)
 Extracts the items from list as long as f evaluates to ML99_true().
#define ML99_listDrop(n, list)
 Removes the prefix of list of the length n.
#define ML99_listDropWhile(f, list)
 Removes the items from list as long as f evaluates to ML99_true().
#define ML99_listZip(list, other)
 Computes a list of two-place tuples of the corresponding items from list and other.
#define 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_listReplicate(n, item)
 Computes a list of length n with each element item.
#define 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_listAppl(f, list)
 Applies all the items in list to f.
#define ML99_CONS(x, xs)
#define ML99_NIL(...)
#define ML99_IS_CONS(list)
#define ML99_IS_NIL(list)

Detailed Description

Cons-lists.

Macro Definition Documentation

◆ ML99_CONS

#define ML99_CONS ( x,
xs )
Value:
ML99_CHOICE(cons, x, xs)

◆ ML99_cons

#define ML99_cons ( x,
xs )
Value:
#define ML99_call(op,...)
Invokes a metafunction with arguments.
Definition lang.h:33
#define ML99_cons(x, xs)
Prepends x to xs.
Definition list.h:30

Prepends x to xs.

Examples

#define v(...)
A value that is pasted as-is; no evaluation occurs on provided arguments.
Definition lang.h:145
Cons-lists.
#define ML99_nil(...)
The empty list.
Definition list.h:35

◆ ML99_IS_CONS

#define ML99_IS_CONS ( list)
Value:
ML99_NOT(ML99_IS_NIL(list))

◆ ML99_IS_NIL

#define ML99_IS_NIL ( list)
Value:
ML99_PRIV_IS_NIL(list)

◆ ML99_isCons

#define ML99_isCons ( list)
Value:
#define ML99_isCons(list)
Checks list for non-emptiness.
Definition list.h:52

Checks list for non-emptiness.

Examples

// 1
// 0
#define ML99_list(...)
Constructs a list from its arguments.
Definition list.h:147

◆ ML99_isNil

#define ML99_isNil ( list)
Value:
#define ML99_isNil(list)
Checks list for emptiness.
Definition list.h:69

Checks list for emptiness.

Examples

// 0
// 1

◆ ML99_list

#define ML99_list ( ...)
Value:
ML99_call(ML99_list, __VA_ARGS__)

Constructs a list from its arguments.

At most 63 arguments are acceptable.

Examples

// 1, 2, 3
ML99_list(v(1, 2, 3))

◆ ML99_LIST_EVAL

#define ML99_LIST_EVAL ( ...)
Value:
#define ML99_EVAL(...)
Evaluates a metaprogram.
Definition lang.h:28
#define ML99_listUnwrap(list)
Places all the items in list as-is.
Definition list.h:290

Evaluates a metaprogram that reduces to a list, then unwraps it.

It behaves the same as the composition of ML99_EVAL and ML99_listUnwrap.

Examples

// Literally 1 2 3
#define ML99_LIST_EVAL(...)
Evaluates a metaprogram that reduces to a list, then unwraps it.
Definition list.h:227
Note
This macro does not result in a Metalang99 term; it literally pastes list elements into a source file.

◆ ML99_LIST_EVAL_COMMA_SEP

#define ML99_LIST_EVAL_COMMA_SEP ( ...)
Value:
#define ML99_listUnwrapCommaSep(list)
Places all the items in list as-is, separated by commas.
Definition list.h:308

The same as ML99_LIST_EVAL but intersperses a comma between list items.

Examples

// Literally 1, 2, 3
#define ML99_LIST_EVAL_COMMA_SEP(...)
The same as ML99_LIST_EVAL but intersperses a comma between list items.
Definition list.h:244
Utilitary stuff.
Note
This macro does not result in a Metalang99 term; it literally pastes comma-separated list elements into a source file.

◆ ML99_listAppend

#define ML99_listAppend ( list,
other )
Value:
#define ML99_listAppend(list, other)
Appends the list other to list.
Definition list.h:258

Appends the list other to list.

Examples

// 1, 2, 3

◆ ML99_listAppendItem

#define ML99_listAppendItem ( item,
list )
Value:
#define ML99_listAppendItem(item, list)
Appends the item item to list.
Definition list.h:272

Appends the item item to list.

Examples

// 1, 2, 3

◆ ML99_listAppl

#define ML99_listAppl ( f,
list )
Value:
#define ML99_listAppl(f, list)
Applies all the items in list to f.
Definition list.h:725

Applies all the items in list to f.

If the list is empty, results in f as-is.

Examples

#include <metalang99/nat.h>
// ML99_add
// ML99_appl(v(ML99_add), v(1))
// ML99_appl2(v(ML99_add), v(1), v(2))
Natural numbers: [0; 255].
#define ML99_add(x, y)
Definition nat.h:211

◆ ML99_listContains

#define ML99_listContains ( cmp,
item,
list )
Value:
ML99_call(ML99_listContains, cmp, item, list)
#define ML99_listContains(cmp, item, list)
Checks whether item resides in list.
Definition list.h:579

Checks whether item resides in list.

Examples

#include <metalang99/nat.h>
// 1
// 0
#define ML99_natEq(x, y)
Definition nat.h:112

◆ ML99_listDrop

#define ML99_listDrop ( n,
list )
Value:
#define ML99_listDrop(n, list)
Removes the prefix of list of the length n.
Definition list.h:624

Removes the prefix of list of the length n.

If n is greater than the length of list, ML99_nil() is returned.

Examples

// 2, 3
ML99_listDrop(v(1), ML99_list(v(1, 2, 3)))

◆ ML99_listDropWhile

#define ML99_listDropWhile ( f,
list )
Value:
#define ML99_listDropWhile(f, list)
Removes the items from list as long as f evaluates to ML99_true().
Definition list.h:639

Removes the items from list as long as f evaluates to ML99_true().

Examples

#include <metalang99/nat.h>
// 4, 5, 6
#define ML99_appl(f,...)
Applies arguments to f.
Definition lang.h:93
#define ML99_lesser(x, y)
Definition nat.h:180

◆ ML99_listEq

#define ML99_listEq ( cmp,
list,
other )
Value:
ML99_call(ML99_listEq, cmp, list, other)
#define ML99_listEq(cmp, list, other)
Tests list and other for equality.
Definition list.h:561

Tests list and other for equality.

Examples

#include <metalang99/nat.h>
// 0
ML99_listEq(v(ML99_natEq), ML99_list(v(1, 2, 3)), ML99_list(v(4, 5, 6)))
// 1
ML99_listEq(v(ML99_natEq), ML99_list(v(1, 2, 3)), ML99_list(v(1, 2, 3)))

◆ ML99_listFilter

#define ML99_listFilter ( f,
list )
Value:
#define ML99_listFilter(f, list)
Filters list with f.
Definition list.h:523

Filters list with f.

Examples

#include <metalang99/nat.h>
// 9, 11, 6
ML99_listFilter(ML99_appl(v(ML99_lesser), v(5)), ML99_list(v(9, 1, 11, 6, 0, 4)))

◆ ML99_listFilterMap

#define ML99_listFilterMap ( f,
list )
Value:
#define ML99_listFilterMap(f, list)
A combination of ML99_listFilter and ML99_listMap.
Definition list.h:543

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.

Examples

#define MAYBE_LIST ML99_list(ML99_just(v(5)), ML99_nothing(), ML99_just(v(7)))
// 5, 7
An optional value.
#define ML99_id(...)
Evaluates to its arguments.
Definition util.h:96

◆ ML99_listFoldl

#define ML99_listFoldl ( f,
init,
list )
Value:
ML99_call(ML99_listFoldl, f, init, list)
#define ML99_listFoldl(f, init, list)
A left-associative fold over list.
Definition list.h:374

A left-associative fold over list.

Examples

#define ABCDEFG 123
// 7
// 123
ML99_listFoldl(v(ML99_cat), v(A), ML99_list(v(BC, DEF, G)))
#define ML99_cat(a, b)
Concatenates a with b, leaving the result unevaluated.
Definition util.h:53

◆ ML99_listFoldl1

#define ML99_listFoldl1 ( f,
list )
Value:
#define ML99_listFoldl1(f, list)
The same as ML99_listFoldl but treats the first element of list as the initial value.
Definition list.h:390

The same as ML99_listFoldl but treats the first element of list as the initial value.

Examples

#define ABCDEFG 123
// 123

◆ ML99_listFoldr

#define ML99_listFoldr ( f,
init,
list )
Value:
ML99_call(ML99_listFoldr, f, init, list)
#define ML99_listFoldr(f, init, list)
A right-associative fold over list.
Definition list.h:355

A right-associative fold over list.

Examples

#define ABCDEFG 123
// 7
// 123
#define ML99_flip(f)
Reverses the order of arguments of the binary function f.
Definition util.h:124

◆ ML99_listFor

#define ML99_listFor ( list,
f )
Value:
#define ML99_listFor(list, f)
The same as ML99_listMap but with the reversed order of arguments.
Definition list.h:479

The same as ML99_listMap but with the reversed order of arguments.

Examples

#include <metalang99/nat.h>
// 4, 5, 6

◆ ML99_listForInitLast

#define ML99_listForInitLast ( list,
f_init,
f_last )
Value:
ML99_call(ML99_listForInitLast, list, f_init, f_last)
#define ML99_listForInitLast(list, f_init, f_last)
The same as ML99_listMapInitLast but accepts list as the first parameter.
Definition list.h:507

The same as ML99_listMapInitLast but accepts list as the first parameter.

Examples

// 4, 5, 10
v(7)))

◆ ML99_listFromSeq

#define ML99_listFromSeq ( seq)
Value:
#define ML99_listFromSeq(seq)
Constructs a list from the sequence seq.
Definition list.h:191

Constructs a list from the sequence seq.

Note that seq items must not contain commas. If you want commas in items, such as (+, -, *, /), consider wrapping an item in parentheses: ((+, -, *, /)).

Examples

// ML99_nil()
// ML99_list(v(1, 2, 3))
ML99_listFromSeq(v((1)(2)(3)))

◆ ML99_listFromTuples

#define ML99_listFromTuples ( f,
... )
Value:
#define ML99_listFromTuples(f,...)
Constructs a list from comma-separated tuples.
Definition list.h:171

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.

Examples

#define F_IMPL(x, y) v(x + y)
#define F_ARITY 1
// ML99_list(v(1 + 2, 3 + 4, 5 + 6))
ML99_listFromTuples(v(F), v((1, 2), (3, 4), (5, 6)))

◆ ML99_listGet

#define ML99_listGet ( i,
list )
Value:
#define ML99_listGet(i, list)
Extracts the i -indexed element.
Definition list.h:336

Extracts the i -indexed element.

Examples

// 2
ML99_listGet(v(1), ML99_list(v(1, 2, 3)))

◆ ML99_listHead

#define ML99_listHead ( list)
Value:
#define ML99_listHead(list)
Extracts the head from the non-empty list list.
Definition list.h:83

Extracts the head from the non-empty list list.

Examples

// 1

◆ ML99_listInit

#define ML99_listInit ( list)
Value:
#define ML99_listInit(list)
Extracts all the elements of the non-empty list list except the last one.
Definition list.h:131

Extracts all the elements of the non-empty list list except the last one.

Examples

// 1, 2
// ML99_nil()

◆ ML99_listIntersperse

#define ML99_listIntersperse ( item,
list )
Value:
#define ML99_listIntersperse(item, list)
Intersperses item between the items in list.
Definition list.h:404

Intersperses item between the items in list.

Examples

// 1, +, 2, +, 3

◆ ML99_listLast

#define ML99_listLast ( list)
Value:
#define ML99_listLast(list)
Extracts the last element from the non-empty list list.
Definition list.h:114

Extracts the last element from the non-empty list list.

Examples

// 3

◆ ML99_listLen

#define ML99_listLen ( list)
Value:
#define ML99_listLen(list)
Computes the length of list.
Definition list.h:208

Computes the length of list.

Examples

// 0
// 3

◆ ML99_listMap

#define ML99_listMap ( f,
list )
Value:
#define ML99_listMap(f, list)
Maps all the elements in list with f.
Definition list.h:433

Maps all the elements in list with f.

Examples

#include <metalang99/nat.h>
// 4, 5, 6

◆ ML99_listMapI

#define ML99_listMapI ( f,
list )
Value:
#define ML99_listMapI(f, list)
The same as ML99_listMap but provides an index of an element to f.
Definition list.h:450

The same as ML99_listMap but provides an index of an element to f.

Examples

#define F_IMPL(x, i) v(x[i])
#define F_ARITY 2
// a[0], b[1], c[2]
ML99_listMapI(v(F), ML99_list(v(a, b, c)))

◆ ML99_listMapInitLast

#define ML99_listMapInitLast ( f_init,
f_last,
list )
Value:
ML99_call(ML99_listMapInitLast, f_init, f_last, list)
#define 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.
Definition list.h:493

Maps the initial elements of the non-empty list list with f_init and the last element with f_last.

Examples

// 4, 5, 10
2, 3)))

◆ ML99_listMapInPlace

#define ML99_listMapInPlace ( f,
list )
Value:
#define ML99_listMapInPlace(f, list)
A more efficient version of ML99_listUnwrap(ML99_listMap(f, list)).
Definition list.h:457

A more efficient version of ML99_listUnwrap(ML99_listMap(f, list)).

Note
Unlike ML99_listMap, f can evaluate to many terms.

◆ ML99_listMapInPlaceI

#define ML99_listMapInPlaceI ( f,
list )
Value:
#define ML99_listMapInPlaceI(f, list)
A more efficient version of ML99_listUnwrap(ML99_listMapI(f, list)).
Definition list.h:464

A more efficient version of ML99_listUnwrap(ML99_listMapI(f, list)).

Note
Unlike ML99_listMapI, f can evaluate to many terms.

◆ ML99_listPartition

#define ML99_listPartition ( f,
list )
Value:
#define ML99_listPartition(f, list)
Returns a two-place tuple of lists: those items of list the do and do not satisfy the predicate f,...
Definition list.h:702

Returns a two-place tuple of lists: those items of list the do and do not satisfy the predicate f, respectively.

Examples

#include <metalang99/nat.h>
// ML99_tuple(ML99_list(v(4, 7)), ML99_list(v(11, 12, 13)))
ML99_listPartition(ML99_appl(v(ML99_greater), v(10)), ML99_list(v(11, 4, 12, 13, 7)))
#define ML99_greater(x, y)
Definition nat.h:146

◆ ML99_listPrependToAll

#define ML99_listPrependToAll ( item,
list )
Value:
#define ML99_listPrependToAll(item, list)
Prepends item to all items in list.
Definition list.h:418

Prepends item to all items in list.

Examples

// +, 1, +, 2, +, 3

◆ ML99_listReplicate

#define ML99_listReplicate ( n,
item )
Value:
#define ML99_listReplicate(n, item)
Computes a list of length n with each element item.
Definition list.h:686

Computes a list of length n with each element item.

Examples

// ~, ~, ~, ~, ~
// ML99_nil()

◆ ML99_listReverse

#define ML99_listReverse ( list)
Value:
#define ML99_listReverse(list)
Reverses the order of items in list.
Definition list.h:322

Reverses the order of items in list.

Examples

// 3, 2, 1

◆ ML99_listTail

#define ML99_listTail ( list)
Value:
#define ML99_listTail(list)
Extracts the tail from the non-empty list list.
Definition list.h:100

Extracts the tail from the non-empty list list.

Examples

// 2, 3
// ML99_nil()

◆ ML99_listTake

#define ML99_listTake ( n,
list )
Value:
#define ML99_listTake(n, list)
Extracts the prefix of list of the length n.
Definition list.h:594

Extracts the prefix of list of the length n.

If n is greater than the length of list, the whole list is returned.

Examples

// 1, 2
ML99_listTake(v(2), ML99_list(v(1, 2, 3)))

◆ ML99_listTakeWhile

#define ML99_listTakeWhile ( f,
list )
Value:
#define ML99_listTakeWhile(f, list)
Extracts the items from list as long as f evaluates to ML99_true().
Definition list.h:609

Extracts the items from list as long as f evaluates to ML99_true().

Examples

#include <metalang99/nat.h>
// 1, 2, 3

◆ ML99_listUnwrap

#define ML99_listUnwrap ( list)
Value:

Places all the items in list as-is.

Examples

// Literally 1 2 3
Note
The resulting value is still a valid Metalang99 term that need to be evaluated further.
See also
ML99_LIST_EVAL
ML99_LIST_EVAL_COMMA_SEP

◆ ML99_listUnwrapCommaSep

#define ML99_listUnwrapCommaSep ( list)
Value:

Places all the items in list as-is, separated by commas.

Examples

// Literally 1, 2, 3
Note
The resulting value is still a valid Metalang99 term that need to be evaluated further.
See also
ML99_LIST_EVAL
ML99_LIST_EVAL_COMMA_SEP

◆ ML99_listUnzip

#define ML99_listUnzip ( list)
Value:
#define ML99_listUnzip(list)
Transforms a list of two-place tuples into a tuple of a list of the first components and a list of th...
Definition list.h:669

Transforms a list of two-place tuples into a tuple of a list of the first components and a list of the second components.

Examples

// ML99_tuple(ML99_list(v(1, 2, 3)), ML99_list(v(4, 5, 6)))
Tuples: (x, y, z).
#define ML99_tuple(...)
Transforms a sequence of arguments into (...).
Definition tuple.h:38

◆ ML99_listZip

#define ML99_listZip ( list,
other )
Value:
ML99_call(ML99_listZip, list, other)
#define ML99_listZip(list, other)
Computes a list of two-place tuples of the corresponding items from list and other.
Definition list.h:653

Computes a list of two-place tuples of the corresponding items from list and other.

Examples

// (1, 4), (2, 5), (3, 6)
ML99_listZip(ML99_list(v(1, 2, 3)), ML99_list(v(4, 5, 6)))

◆ ML99_NIL

#define ML99_NIL ( ...)
Value:
ML99_CHOICE(nil, ~)

◆ ML99_nil

#define ML99_nil ( ...)
Value:
#define ML99_callUneval(ident,...)
Invokes a metafunction ident with unevaluated arguments.
Definition lang.h:42

The empty list.