Lists: Difference between revisions
No edit summary |
Wikiservice (talk | contribs) (Refresh MemCP documentation: accuracy, operational guidance, performance profile and maintained API reference) |
||
| Line 1: | Line 1: | ||
<!-- Copyright (C) 2026 Carl-Philip Haensch --> | |||
<!-- SPDX-License-Identifier: GPL-3.0-or-later --> | |||
<span id="lists"></span> | |||
= Lists = | = Lists = | ||
<!-- Generated from MemCP c42e19eba on 2026-08-27; do not edit manually. --> | |||
<div class="mw-message-box mw-message-box-notice">Generated from MemCP commit <code>c42e19eba</code> on 27 August 2026. See [[Full SCM API documentation]].</div> | |||
The '''Lists''' module provides the primary collection and code representation used by MemCP Scheme. It includes: | |||
* construction with <code>list</code>, <code>cons</code>, 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 == | == list == | ||
| Line 29: | Line 32: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== count == | == count == | ||
| Line 45: | Line 48: | ||
=== Returns === | === Returns === | ||
<code>int</code> | * '''value''' (<code>int</code>) | ||
== nth == | == nth == | ||
| Line 62: | Line 65: | ||
=== Returns === | === Returns === | ||
<code>any</code> | * '''value''' (<code>any</code>) | ||
== slice == | == slice == | ||
| Line 80: | Line 83: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== reverse == | == reverse == | ||
| Line 96: | Line 99: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== append == | == append == | ||
| Line 113: | Line 116: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== append_unique == | == append_unique == | ||
| Line 130: | Line 133: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== cons == | == cons == | ||
| Line 147: | Line 150: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== car == | == car == | ||
| Line 163: | Line 166: | ||
=== Returns === | === Returns === | ||
<code>any</code> | * '''value''' (<code>any</code>) | ||
== cdr == | == cdr == | ||
| Line 179: | Line 182: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== cadr == | == cadr == | ||
| Line 195: | Line 198: | ||
=== Returns === | === Returns === | ||
<code>any</code> | * '''value''' (<code>any</code>) | ||
== zip == | == zip == | ||
| Line 211: | Line 214: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== merge == | == merge == | ||
| Line 227: | Line 230: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== merge_unique == | == merge_unique == | ||
| Line 243: | Line 246: | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
<span id="has"></span> | <span id="has"></span> | ||
| Line 261: | Line 264: | ||
=== Returns === | === Returns === | ||
<code>bool</code> | * '''value''' (<code>bool</code>) | ||
== filter == | == filter == | ||
| Line 273: | Line 276: | ||
* '''list''' (<code>list</code>): list that has to be filtered | * '''list''' (<code>list</code>): list that has to be filtered | ||
* '''condition''' (<code>func( | * '''condition''' (<code>func</code>): returns whether an item should be included | ||
** '''Parameters''' | |||
*** '''item''' (<code>any</code>): current list item | |||
** '''Returns''' | |||
*** '''included''' (<code>bool</code>): whether to include the item | |||
<span id="returns-15"></span> | <span id="returns-15"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== find == | == find == | ||
| Line 290: | Line 297: | ||
* '''list''' (<code>list</code>): list to search | * '''list''' (<code>list</code>): list to search | ||
* '''condition''' (<code>func | * '''condition''' (<code>func</code>): predicate applied until the first match | ||
** '''Parameters''' | |||
*** '''item''' (<code>any</code>): current list item | |||
** '''Returns''' | |||
*** '''matches''' (<code>bool</code>): whether the item matches | |||
* '''default''' (<code>any</code>): optional default value if nothing matches ''(optional)'' | * '''default''' (<code>any</code>): optional default value if nothing matches ''(optional)'' | ||
| Line 296: | Line 307: | ||
=== Returns === | === Returns === | ||
<code>any</code> | * '''value''' (<code>any</code>) | ||
== map == | == map == | ||
| Line 308: | Line 319: | ||
* '''list''' (<code>list</code>): list that has to be mapped | * '''list''' (<code>list</code>): list that has to be mapped | ||
* '''map''' (<code>func( | * '''map''' (<code>func</code>): transforms each item | ||
** '''Parameters''' | |||
*** '''item''' (<code>any</code>): current list item | |||
** '''Returns''' | |||
*** '''mapped_item''' (<code>any</code>): transformed item | |||
<span id="returns-17"></span> | <span id="returns-17"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== parallel_map == | == parallel_map == | ||
| Line 325: | Line 340: | ||
* '''list''' (<code>list</code>): list to map over in parallel | * '''list''' (<code>list</code>): list to map over in parallel | ||
* '''fn''' (<code>func | * '''fn''' (<code>func</code>): function applied to each element | ||
** '''Parameters''' | |||
*** '''item''' (<code>any</code>) | |||
** '''Returns''' | |||
*** '''value''' (<code>any</code>) | |||
<span id="returns-18"></span> | <span id="returns-18"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== parallel_map_mut == | == parallel_map_mut == | ||
| Line 342: | Line 361: | ||
* '''list''' (<code>list</code>): list to map over in parallel | * '''list''' (<code>list</code>): list to map over in parallel | ||
* '''fn''' (<code>func | * '''fn''' (<code>func</code>): function with side effects applied to each element | ||
** '''Parameters''' | |||
*** '''item''' (<code>any</code>) | |||
** '''Returns''' | |||
*** '''value''' (<code>any</code>) | |||
<span id="returns-19"></span> | <span id="returns-19"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
<span id="mapindex"></span> | <span id="mapindex"></span> | ||
| Line 360: | Line 383: | ||
* '''list''' (<code>list</code>): list that has to be mapped | * '''list''' (<code>list</code>): list that has to be mapped | ||
* '''map''' (<code>func( | * '''map''' (<code>func</code>): transforms each item with its index | ||
** '''Parameters''' | |||
*** '''index''' (<code>int</code>): zero-based item index | |||
*** '''item''' (<code>any</code>): current list item | |||
** '''Returns''' | |||
*** '''mapped_item''' (<code>any</code>): transformed item | |||
<span id="returns-20"></span> | <span id="returns-20"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
== reduce == | == reduce == | ||
| Line 377: | Line 405: | ||
* '''list''' (<code>list</code>): list that has to be reduced | * '''list''' (<code>list</code>): list that has to be reduced | ||
* '''reduce''' (<code>func | * '''reduce''' (<code>func</code>): combines the accumulator with each list item | ||
** '''Parameters''' | |||
*** '''acc''' (<code>any</code>): current accumulator | |||
*** '''item''' (<code>any</code>): current list item | |||
** '''Returns''' | |||
*** '''acc''' (<code>any</code>): next accumulator | |||
* '''neutral''' (<code>any</code>): (optional) initial value of the accumulator, defaults to nil ''(optional)'' | * '''neutral''' (<code>any</code>): (optional) initial value of the accumulator, defaults to nil ''(optional)'' | ||
| Line 383: | Line 416: | ||
=== Returns === | === Returns === | ||
<code>any</code> | * '''value''' (<code>any</code>) | ||
== produce == | == produce == | ||
| Line 395: | Line 428: | ||
* '''startstate''' (<code>any</code>): start state to begin with | * '''startstate''' (<code>any</code>): start state to begin with | ||
* '''condition''' (<code>func | * '''condition''' (<code>func</code>): func that returns true whether the state will be inserted into the result or the loop is stopped | ||
* '''iterator''' (<code>func | ** '''Parameters''' | ||
*** '''state''' (<code>any</code>) | |||
** '''Returns''' | |||
*** '''value''' (<code>bool</code>) | |||
* '''iterator''' (<code>func</code>): func that produces the next state | |||
** '''Parameters''' | |||
*** '''state''' (<code>any</code>) | |||
** '''Returns''' | |||
*** '''value''' (<code>any</code>) | |||
<span id="returns-22"></span> | <span id="returns-22"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
<span id="producen"></span> | <span id="producen"></span> | ||
| Line 414: | Line 455: | ||
* '''n''' (<code>number</code>): number of elements to produce | * '''n''' (<code>number</code>): number of elements to produce | ||
* '''fn''' (<code>func | * '''fn''' (<code>func</code>): (optional) map function applied to each index ''(optional)'' | ||
** '''Parameters''' | |||
*** '''index''' (<code>int</code>) | |||
** '''Returns''' | |||
*** '''value''' (<code>any</code>) | |||
<span id="returns-23"></span> | <span id="returns-23"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
<span id="paralleln"></span> | <span id="paralleln"></span> | ||
| Line 432: | Line 477: | ||
* '''n''' (<code>number</code>): number of elements to produce | * '''n''' (<code>number</code>): number of elements to produce | ||
* '''fn''' (<code>func | * '''fn''' (<code>func</code>): map function applied to each index in parallel | ||
** '''Parameters''' | |||
*** '''index''' (<code>int</code>) | |||
** '''Returns''' | |||
*** '''value''' (<code>any</code>) | |||
<span id="returns-24"></span> | <span id="returns-24"></span> | ||
=== Returns === | === Returns === | ||
<code>list</code> | * '''value''' (<code>list</code>) | ||
<span id="list-1"></span> | <span id="list-1"></span> | ||
| Line 454: | Line 503: | ||
=== Returns === | === Returns === | ||
<code>bool</code> | * '''value''' (<code>bool</code>) | ||
<span id="contains"></span> | <span id="contains"></span> | ||
| Line 472: | Line 521: | ||
=== Returns === | === Returns === | ||
<code>bool</code> | * '''value''' (<code>bool</code>) | ||
== sql_in == | == sql_in == | ||
| Line 489: | Line 538: | ||
=== Returns === | === Returns === | ||
<code>bool</code> | * '''value''' (<code>bool</code>) | ||
Latest revision as of 11:59, 28 August 2026
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)