lib/typed-list.x
Typed cons chains generated from typed methods.
Primary API
| Function | Summary |
|---|---|
List.listchar | Validates xs as ListChar and returns the identical canonical chain. |
List.listdbl | Validates xs as ListDbl and returns the identical canonical chain. |
List.listfloat | Validates xs as ListFloat and returns the identical canonical chain. |
List.listint | Validates xs as ListInt and returns the identical canonical chain. |
List.listshort | Validates xs as ListShort and returns the identical canonical chain. |
List.liststring | Validates xs as ListString and returns the identical canonical chain. |
List.listsymbol | Validates xs as ListSymbol and returns the identical canonical chain. |
ListChar.car | Returns the first char in xs, or 0 when xs is nil. |
ListChar.cons | Returns the canonical ListChar formed by prepending value to tail. |
ListChar.index | Returns the first zero-based index of value, or -1 when absent. |
ListChar.last | Returns the final char in xs, or 0 when xs is nil, after an O(n) walk. |
ListDbl.car | Returns the first double in xs, or 0.0 when xs is nil. |
ListDbl.cons | Returns the canonical ListDbl formed by prepending value to tail. |
ListDbl.index | Returns the first zero-based index of value, or -1 when absent. |
ListDbl.last | Returns the final double in xs, or 0.0 when xs is nil, after an O(n) walk. |
ListFloat.car | Returns the first float in xs, or 0.0f when xs is nil. |
ListFloat.cons | Returns the canonical ListFloat formed by prepending value to tail. |
ListFloat.index | Returns the first zero-based index of value, or -1 when absent. |
ListFloat.last | Returns the final float in xs, or 0.0f when xs is nil, after an O(n) walk. |
ListInt.car | Returns the first int in xs, or 0 when xs is nil. |
ListInt.cons | Returns the canonical ListInt formed by prepending value to tail. |
ListInt.index | Returns the first zero-based index of value, or -1 when absent. |
ListInt.last | Returns the final int in xs, or 0 when xs is nil, after an O(n) walk. |
ListShort.car | Returns the first short in xs, or 0 when xs is nil. |
ListShort.cons | Returns the canonical ListShort formed by prepending value to tail. |
ListShort.index | Returns the first zero-based index of value, or -1 when absent. |
ListShort.last | Returns the final short in xs, or 0 when xs is nil, after an O(n) walk. |
ListString.car | Returns the first String in xs, or NULL when xs is nil. |
ListString.cons | Returns the canonical ListString formed by prepending value to tail. |
ListString.index | Returns the first zero-based index of value, or -1 when absent. |
ListString.last | Returns the final String in xs, or NULL when xs is nil, after an O(n) walk. |
ListSymbol.car | Returns the first Symbol in xs, or 0 when xs is nil. |
ListSymbol.cons | Returns the canonical ListSymbol formed by prepending value to tail. |
ListSymbol.index | Returns the first zero-based index of value, or -1 when absent. |
ListSymbol.last | Returns the final Symbol in xs, or 0 when xs is nil, after an O(n) walk. |
Var.listchar | Extracts and validates value as ListChar without copying its cells. |
Var.listdbl | Extracts and validates value as ListDbl without copying its cells. |
Var.listfloat | Extracts and validates value as ListFloat without copying its cells. |
Var.listint | Extracts and validates value as ListInt without copying its cells. |
Var.listshort | Extracts and validates value as ListShort without copying its cells. |
Var.liststring | Extracts and validates value as ListString without copying its cells. |
Var.listsymbol | Extracts and validates value as ListSymbol without copying its cells. |
List
List.listchar
ListChar List.listchar(List xs)
Validates xs as ListChar and returns the identical canonical chain.
Nil is valid. Every nonempty cell must hold a <i8> element; a foreign
tag raises <no-convert> with its zero-based index. Validation is O(n),
does not copy or mutate cells, and preserves their existing List-pool
lifetime.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:97
List.listdbl
ListDbl List.listdbl(List xs)
Validates xs as ListDbl and returns the identical canonical chain.
Nil is valid. Every nonempty cell must hold a <f64> element; a foreign
tag raises <no-convert> with its zero-based index. Validation is O(n),
does not copy or mutate cells, and preserves their existing List-pool
lifetime.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:113
List.listfloat
ListFloat List.listfloat(List xs)
Validates xs as ListFloat and returns the identical canonical chain.
Nil is valid. Every nonempty cell must hold a <f32> element; a foreign
tag raises <no-convert> with its zero-based index. Validation is O(n),
does not copy or mutate cells, and preserves their existing List-pool
lifetime.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:109
List.listint
ListInt List.listint(List xs)
Validates xs as ListInt and returns the identical canonical chain.
Nil is valid. Every nonempty cell must hold a <i32> element; a foreign
tag raises <no-convert> with its zero-based index. Validation is O(n),
does not copy or mutate cells, and preserves their existing List-pool
lifetime.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:105
List.listshort
ListShort List.listshort(List xs)
Validates xs as ListShort and returns the identical canonical chain.
Nil is valid. Every nonempty cell must hold a <i16> element; a foreign
tag raises <no-convert> with its zero-based index. Validation is O(n),
does not copy or mutate cells, and preserves their existing List-pool
lifetime.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:101
List.liststring
ListString List.liststring(List xs)
Validates xs as ListString and returns the identical canonical chain.
Nil is valid. Every nonempty cell must hold a <string> element; a foreign
tag raises <no-convert> with its zero-based index. Validation is O(n),
does not copy or mutate cells, and preserves their existing List-pool
lifetime.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:117
List.listsymbol
ListSymbol List.listsymbol(List xs)
Validates xs as ListSymbol and returns the identical canonical chain.
Nil is valid. Every nonempty cell must hold a <symbol> element; a foreign
tag raises <no-convert> with its zero-based index. Validation is O(n),
does not copy or mutate cells, and preserves their existing List-pool
lifetime.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:121
ListChar
ListChar.car
inline char ListChar.car(ListChar xs)
Returns the first char in xs, or 0 when xs is nil.
A nonempty xs must retain the ListChar element-tag invariant.
Source: lib/typed-list.x:97
ListChar.cons
inline ListChar ListChar.cons(char value, ListChar tail)
Returns the canonical ListChar formed by prepending value to tail.
The immutable tail is shared. The result follows the lifetime of its
owning canonical List pool, which may be an ancestor of the current
pool when an existing cell is reused.
Raises: <alloc-fail> or <size-limit> while installing a new
canonical cell.
Source: lib/typed-list.x:97
ListChar.index
int ListChar.index(ListChar xs, char value)
Returns the first zero-based index of value, or -1 when absent.
Source: lib/typed-list.x:97
ListChar.last
char ListChar.last(ListChar xs)
Returns the final char in xs, or 0 when xs is nil,
after an O(n) walk.
A nonempty xs must retain the ListChar element-tag invariant.
Source: lib/typed-list.x:97
ListDbl
ListDbl.car
inline double ListDbl.car(ListDbl xs)
Returns the first double in xs, or 0.0 when xs is nil.
A nonempty xs must retain the ListDbl element-tag invariant.
Source: lib/typed-list.x:113
ListDbl.cons
inline ListDbl ListDbl.cons(double value, ListDbl tail)
Returns the canonical ListDbl formed by prepending value to tail.
The immutable tail is shared. The result follows the lifetime of its
owning canonical List pool, which may be an ancestor of the current
pool when an existing cell is reused.
Raises: <alloc-fail> or <size-limit> while installing a new
canonical cell.
Source: lib/typed-list.x:113
ListDbl.index
int ListDbl.index(ListDbl xs, double value)
Returns the first zero-based index of value, or -1 when absent.
Source: lib/typed-list.x:113
ListDbl.last
double ListDbl.last(ListDbl xs)
Returns the final double in xs, or 0.0 when xs is nil,
after an O(n) walk.
A nonempty xs must retain the ListDbl element-tag invariant.
Source: lib/typed-list.x:113
ListFloat
ListFloat.car
inline float ListFloat.car(ListFloat xs)
Returns the first float in xs, or 0.0f when xs is nil.
A nonempty xs must retain the ListFloat element-tag invariant.
Source: lib/typed-list.x:109
ListFloat.cons
inline ListFloat ListFloat.cons(float value, ListFloat tail)
Returns the canonical ListFloat formed by prepending value to tail.
The immutable tail is shared. The result follows the lifetime of its
owning canonical List pool, which may be an ancestor of the current
pool when an existing cell is reused.
Raises: <alloc-fail> or <size-limit> while installing a new
canonical cell.
Source: lib/typed-list.x:109
ListFloat.index
int ListFloat.index(ListFloat xs, float value)
Returns the first zero-based index of value, or -1 when absent.
Source: lib/typed-list.x:109
ListFloat.last
float ListFloat.last(ListFloat xs)
Returns the final float in xs, or 0.0f when xs is nil,
after an O(n) walk.
A nonempty xs must retain the ListFloat element-tag invariant.
Source: lib/typed-list.x:109
ListInt
ListInt.car
inline int ListInt.car(ListInt xs)
Returns the first int in xs, or 0 when xs is nil.
A nonempty xs must retain the ListInt element-tag invariant.
Source: lib/typed-list.x:105
ListInt.cons
inline ListInt ListInt.cons(int value, ListInt tail)
Returns the canonical ListInt formed by prepending value to tail.
The immutable tail is shared. The result follows the lifetime of its
owning canonical List pool, which may be an ancestor of the current
pool when an existing cell is reused.
Raises: <alloc-fail> or <size-limit> while installing a new
canonical cell.
Source: lib/typed-list.x:105
ListInt.index
int ListInt.index(ListInt xs, int value)
Returns the first zero-based index of value, or -1 when absent.
Source: lib/typed-list.x:105
ListInt.last
int ListInt.last(ListInt xs)
Returns the final int in xs, or 0 when xs is nil,
after an O(n) walk.
A nonempty xs must retain the ListInt element-tag invariant.
Source: lib/typed-list.x:105
ListShort
ListShort.car
inline short ListShort.car(ListShort xs)
Returns the first short in xs, or 0 when xs is nil.
A nonempty xs must retain the ListShort element-tag invariant.
Source: lib/typed-list.x:101
ListShort.cons
inline ListShort ListShort.cons(short value, ListShort tail)
Returns the canonical ListShort formed by prepending value to tail.
The immutable tail is shared. The result follows the lifetime of its
owning canonical List pool, which may be an ancestor of the current
pool when an existing cell is reused.
Raises: <alloc-fail> or <size-limit> while installing a new
canonical cell.
Source: lib/typed-list.x:101
ListShort.index
int ListShort.index(ListShort xs, short value)
Returns the first zero-based index of value, or -1 when absent.
Source: lib/typed-list.x:101
ListShort.last
short ListShort.last(ListShort xs)
Returns the final short in xs, or 0 when xs is nil,
after an O(n) walk.
A nonempty xs must retain the ListShort element-tag invariant.
Source: lib/typed-list.x:101
ListString
ListString.car
inline String ListString.car(ListString xs)
Returns the first String in xs, or NULL when xs is nil.
A nonempty xs must retain the ListString element-tag invariant.
Source: lib/typed-list.x:117
ListString.cons
inline ListString ListString.cons(String value, ListString tail)
Returns the canonical ListString formed by prepending value to tail.
The immutable tail is shared. The result follows the lifetime of its
owning canonical List pool, which may be an ancestor of the current
pool when an existing cell is reused.
Raises: <alloc-fail> or <size-limit> while installing a new
canonical cell.
Source: lib/typed-list.x:117
ListString.index
int ListString.index(ListString xs, String value)
Returns the first zero-based index of value, or -1 when absent.
Source: lib/typed-list.x:117
ListString.last
String ListString.last(ListString xs)
Returns the final String in xs, or NULL when xs is nil,
after an O(n) walk.
A nonempty xs must retain the ListString element-tag invariant.
Source: lib/typed-list.x:117
ListSymbol
ListSymbol.car
inline Symbol ListSymbol.car(ListSymbol xs)
Returns the first Symbol in xs, or 0 when xs is nil.
A nonempty xs must retain the ListSymbol element-tag invariant.
Source: lib/typed-list.x:121
ListSymbol.cons
inline ListSymbol ListSymbol.cons(Symbol value, ListSymbol tail)
Returns the canonical ListSymbol formed by prepending value to tail.
The immutable tail is shared. The result follows the lifetime of its
owning canonical List pool, which may be an ancestor of the current
pool when an existing cell is reused.
Raises: <alloc-fail> or <size-limit> while installing a new
canonical cell.
Source: lib/typed-list.x:121
ListSymbol.index
int ListSymbol.index(ListSymbol xs, Symbol value)
Returns the first zero-based index of value, or -1 when absent.
Source: lib/typed-list.x:121
ListSymbol.last
Symbol ListSymbol.last(ListSymbol xs)
Returns the final Symbol in xs, or 0 when xs is nil,
after an O(n) walk.
A nonempty xs must retain the ListSymbol element-tag invariant.
Source: lib/typed-list.x:121
Var
Var.listchar
ListChar Var.listchar(Var value)
Extracts and validates value as ListChar without copying its cells.
A Var without the <list> tag becomes nil. A List
payload follows the
same element validation, identity, and lifetime rules as List.listchar.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:97
Var.listdbl
ListDbl Var.listdbl(Var value)
Extracts and validates value as ListDbl without copying its cells.
A Var without the <list> tag becomes nil. A List
payload follows the
same element validation, identity, and lifetime rules as List.listdbl.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:113
Var.listfloat
ListFloat Var.listfloat(Var value)
Extracts and validates value as ListFloat without copying its cells.
A Var without the <list> tag becomes nil. A List
payload follows the
same element validation, identity, and lifetime rules as List.listfloat.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:109
Var.listint
ListInt Var.listint(Var value)
Extracts and validates value as ListInt without copying its cells.
A Var without the <list> tag becomes nil. A List
payload follows the
same element validation, identity, and lifetime rules as List.listint.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:105
Var.listshort
ListShort Var.listshort(Var value)
Extracts and validates value as ListShort without copying its cells.
A Var without the <list> tag becomes nil. A List
payload follows the
same element validation, identity, and lifetime rules as List.listshort.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:101
Var.liststring
ListString Var.liststring(Var value)
Extracts and validates value as ListString without copying its cells.
A Var without the <list> tag becomes nil. A List
payload follows the
same element validation, identity, and lifetime rules as List.liststring.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:117
Var.listsymbol
ListSymbol Var.listsymbol(Var value)
Extracts and validates value as ListSymbol without copying its cells.
A Var without the <list> tag becomes nil. A List
payload follows the
same element validation, identity, and lifetime rules as List.listsymbol.
Raises: <no-convert> for the first foreign element.
Source: lib/typed-list.x:121
Public types
| Type | Kind | Summary |
|---|---|---|
ListChar | alias | Typed view of canonical List cells whose cars are <i8> char values. |
ListDbl | alias | Typed view of canonical List cells whose cars are <f64> double values. |
ListFloat | alias | Typed view of canonical List cells whose cars are <f32> float values. |
ListInt | alias | Typed view of canonical List cells whose cars are <i32> int values. |
ListShort | alias | Typed view of canonical List cells whose cars are <i16> short values. |
ListString | alias | Typed view of canonical List cells whose cars are <string> Strings. |
ListSymbol | alias | Typed view of canonical List cells whose cars are <symbol> Symbols. |
ListChar
typedef List ListChar
Typed view of canonical List cells whose cars are <i8> char values.
Source: lib/typed-list.x:28
ListDbl
typedef List ListDbl
Typed view of canonical List cells whose cars are <f64> double values.
Source: lib/typed-list.x:39
ListFloat
typedef List ListFloat
Typed view of canonical List cells whose cars are <f32> float values.
Source: lib/typed-list.x:36
ListInt
typedef List ListInt
Typed view of canonical List cells whose cars are <i32> int values.
Source: lib/typed-list.x:33
ListShort
typedef List ListShort
Typed view of canonical List cells whose cars are <i16> short values.
Source: lib/typed-list.x:31
ListString
typedef List ListString
Typed view of canonical List cells whose cars are <string> Strings.
Source: lib/typed-list.x:42
ListSymbol
typedef List ListSymbol
Typed view of canonical List cells whose cars are <symbol> Symbols.
Source: lib/typed-list.x:45
Design notes
A typed list is a List whose car always carries one known Var tag. It
shares List’s canonical pool, so a typed chain and the plain literal that
spells it are the same cells, and a typed cons finds a cell an untyped
cons already built.
A typed chain costs what an untyped one costs. cons searches the pool
and, on a miss, allocates and inserts a cell. ArrayInt.push copies an
element into contiguous storage. Use typed-array.x for indexing or bulk
numeric storage, and typed lists for shared tails and canonical identity.
There is no long family. Var.box_long allocates a Scope-owned box, so a
cell outliving that scope would hold a dangling car, and List.equal
compares car bits. Two boxes of one number differ, so every cons would
miss and the interning table would grow without bound.
Tests and examples
make verify (unittest/test-typed-list.x).