Lists
Lists
The Lists module provides the primary collection and code representation used by MemCP Scheme. It includes:
- construction with
list,cons, append, merge, and zip operations; - access through count, head/tail, indexed lookup, searching, and containment checks;
- functional transformation with map, filter, reduce, flattening, and deduplication;
- generation of ranges and computed sequences;
- ownership-aware internal variants used by optimized generated plans.
Lists are immutable at the language level. Quoted lists can represent data or delayed Scheme code; see Introduction to Scheme for quoting and evaluation rules.
list
constructs a list from its arguments
Allowed number of parameters: 0–10000
Parameters
- items (
any): items to put into the list (variadic)
Returns
- value (
list)
count
counts the number of elements in the list
Allowed number of parameters: 1–1
Parameters
- list (
list): base list
Returns
- value (
int)
nth
get the nth item of a list
Allowed number of parameters: 2–2
Parameters
- list (
list): base list - index (
number): index beginning from 0
Returns
- value (
any)
slice
extract a sublist from start (inclusive) to end (exclusive). (slice list start end) returns elements list[start..end).
Allowed number of parameters: 3–3
Parameters
- list (
list): base list - start (
number): start index (inclusive) - end (
number): end index (exclusive)
Returns
- value (
list)
reverse
returns a new list with elements in reversed order.
Allowed number of parameters: 1–1
Parameters
- list (
list): list to reverse
Returns
- value (
list)
append
appends items to a list and return the extended list. The original list stays unharmed.
Allowed number of parameters: 1–10000
Parameters
- list (
list): base list - item... (
any): items to add (variadic)
Returns
- value (
list)
append_unique
appends items to a list but only if they are new. The original list stays unharmed.
Allowed number of parameters: 1–10000
Parameters
- list (
list): base list - item... (
any): items to add (variadic)
Returns
- value (
list)
cons
constructs a list from a head and a tail list
Allowed number of parameters: 2–2
Parameters
- car (
any): new head element - cdr (
list): tail that is appended after car
Returns
- value (
list)
car
extracts the head of a list
Allowed number of parameters: 1–1
Parameters
- list (
list): list
Returns
- value (
any)
cdr
extracts the tail of a list The tail of a list is a list with all items except the head.
Allowed number of parameters: 1–1
Parameters
- list (
list): list
Returns
- value (
list)
cadr
extracts the second element of a list. Equivalent to (car (cdr x)).
Allowed number of parameters: 1–1
Parameters
- list (
list): list
Returns
- value (
any)
zip
swaps the dimension of a list of lists. If one parameter is given, it is a list of lists that is flattened. If multiple parameters are given, they are treated as the components that will be zipped into the sub list
Allowed number of parameters: 0–10000
Parameters
- list (
any): list of lists of items (variadic)
Returns
- value (
list)
merge
flattens a list of lists into a list containing all the subitems. If one parameter is given, it is a list of lists that is flattened. If multiple parameters are given, they are treated as lists that will be merged into one
Allowed number of parameters: 0–10000
Parameters
- list (
any): list of lists of items (variadic)
Returns
- value (
list)
merge_unique
flattens a list of lists into a list containing all the subitems. Duplicates are filtered out.
Allowed number of parameters: 0–10000
Parameters
- list (
list): list of lists of items (variadic)
Returns
- value (
list)
has?
checks if a list has a certain item (equal?)
Allowed number of parameters: 2–2
Parameters
- haystack (
list): list to search in - needle (
any): item to search for
Returns
- value (
bool)
filter
returns a list that only contains elements that pass the filter function
Allowed number of parameters: 2–2
Parameters
- list (
list): list that has to be filtered - condition (
func): returns whether an item should be included- Parameters
- item (
any): current list item
- item (
- Returns
- included (
bool): whether to include the item
- included (
- Parameters
Returns
- value (
list)
find
returns the first list element that passes the condition function, or nil/default if none matches
Allowed number of parameters: 2–3
Parameters
- list (
list): list to search - condition (
func): predicate applied until the first match- Parameters
- item (
any): current list item
- item (
- Returns
- matches (
bool): whether the item matches
- matches (
- Parameters
- default (
any): optional default value if nothing matches (optional)
Returns
- value (
any)
map
returns a list that contains the results of a map function that is applied to the list
Allowed number of parameters: 2–2
Parameters
- list (
list): list that has to be mapped - map (
func): transforms each item- Parameters
- item (
any): current list item
- item (
- Returns
- mapped_item (
any): transformed item
- mapped_item (
- Parameters
Returns
- value (
list)
parallel_map
like map, but applies fn to each element in parallel using a worker pool limited to runtime.NumCPU()
Allowed number of parameters: 2–2
Parameters
- list (
list): list to map over in parallel - fn (
func): function applied to each element- Parameters
- item (
any)
- item (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
list)
parallel_map_mut
like parallel_map, but signals the optimizer that fn may have side effects
Allowed number of parameters: 2–2
Parameters
- list (
list): list to map over in parallel - fn (
func): function with side effects applied to each element- Parameters
- item (
any)
- item (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
list)
mapIndex
returns a list that contains the results of a map function that is applied to the list
Allowed number of parameters: 2–2
Parameters
- list (
list): list that has to be mapped - map (
func): transforms each item with its index- Parameters
- index (
int): zero-based item index - item (
any): current list item
- index (
- Returns
- mapped_item (
any): transformed item
- mapped_item (
- Parameters
Returns
- value (
list)
reduce
returns a list that contains the result of a map function
Allowed number of parameters: 2–3
Parameters
- list (
list): list that has to be reduced - reduce (
func): combines the accumulator with each list item- Parameters
- acc (
any): current accumulator - item (
any): current list item
- acc (
- Returns
- acc (
any): next accumulator
- acc (
- Parameters
- neutral (
any): (optional) initial value of the accumulator, defaults to nil (optional)
Returns
- value (
any)
produce
returns a list that contains produced items - it works like for(state = startstate, condition(state), state = iterator(state)) {yield state}
Allowed number of parameters: 3–3
Parameters
- startstate (
any): start state to begin with - condition (
func): func that returns true whether the state will be inserted into the result or the loop is stopped- Parameters
- state (
any)
- state (
- Returns
- value (
bool)
- value (
- Parameters
- iterator (
func): func that produces the next state- Parameters
- state (
any)
- state (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
list)
produceN
returns a list with numbers from 0..n-1, optionally mapped through a function
Allowed number of parameters: 1–2
Parameters
- n (
number): number of elements to produce - fn (
func): (optional) map function applied to each index (optional)- Parameters
- index (
int)
- index (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
list)
parallelN
returns a list with numbers from 0..n-1 mapped in parallel through a function
Allowed number of parameters: 2–2
Parameters
- n (
number): number of elements to produce - fn (
func): map function applied to each index in parallel- Parameters
- index (
int)
- index (
- Returns
- value (
any)
- value (
- Parameters
Returns
- value (
list)
list?
checks if a value is a list
Allowed number of parameters: 1–1
Parameters
- value (
any): value to check
Returns
- value (
bool)
contains?
checks if a value is in a list; uses the equal?? operator
Allowed number of parameters: 2–2
Parameters
- list (
list): list to check - value (
any): value to check
Returns
- value (
bool)
sql_in
tests SQL IN-list membership and returns nil when NULL makes the result UNKNOWN
Allowed number of parameters: 2–2
Parameters
- values (
list): SQL IN-list values - value (
any): value to find
Returns
- value (
bool)