Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

lib/typed-list.x

Typed cons chains generated from typed methods.

Primary API

FunctionSummary
List.listcharValidates xs as ListChar and returns the identical canonical chain.
List.listdblValidates xs as ListDbl and returns the identical canonical chain.
List.listfloatValidates xs as ListFloat and returns the identical canonical chain.
List.listintValidates xs as ListInt and returns the identical canonical chain.
List.listshortValidates xs as ListShort and returns the identical canonical chain.
List.liststringValidates xs as ListString and returns the identical canonical chain.
List.listsymbolValidates xs as ListSymbol and returns the identical canonical chain.
ListChar.carReturns the first char in xs, or 0 when xs is nil.
ListChar.consReturns the canonical ListChar formed by prepending value to tail.
ListChar.indexReturns the first zero-based index of value, or -1 when absent.
ListChar.lastReturns the final char in xs, or 0 when xs is nil, after an O(n) walk.
ListDbl.carReturns the first double in xs, or 0.0 when xs is nil.
ListDbl.consReturns the canonical ListDbl formed by prepending value to tail.
ListDbl.indexReturns the first zero-based index of value, or -1 when absent.
ListDbl.lastReturns the final double in xs, or 0.0 when xs is nil, after an O(n) walk.
ListFloat.carReturns the first float in xs, or 0.0f when xs is nil.
ListFloat.consReturns the canonical ListFloat formed by prepending value to tail.
ListFloat.indexReturns the first zero-based index of value, or -1 when absent.
ListFloat.lastReturns the final float in xs, or 0.0f when xs is nil, after an O(n) walk.
ListInt.carReturns the first int in xs, or 0 when xs is nil.
ListInt.consReturns the canonical ListInt formed by prepending value to tail.
ListInt.indexReturns the first zero-based index of value, or -1 when absent.
ListInt.lastReturns the final int in xs, or 0 when xs is nil, after an O(n) walk.
ListShort.carReturns the first short in xs, or 0 when xs is nil.
ListShort.consReturns the canonical ListShort formed by prepending value to tail.
ListShort.indexReturns the first zero-based index of value, or -1 when absent.
ListShort.lastReturns the final short in xs, or 0 when xs is nil, after an O(n) walk.
ListString.carReturns the first String in xs, or NULL when xs is nil.
ListString.consReturns the canonical ListString formed by prepending value to tail.
ListString.indexReturns the first zero-based index of value, or -1 when absent.
ListString.lastReturns the final String in xs, or NULL when xs is nil, after an O(n) walk.
ListSymbol.carReturns the first Symbol in xs, or 0 when xs is nil.
ListSymbol.consReturns the canonical ListSymbol formed by prepending value to tail.
ListSymbol.indexReturns the first zero-based index of value, or -1 when absent.
ListSymbol.lastReturns the final Symbol in xs, or 0 when xs is nil, after an O(n) walk.
Var.listcharExtracts and validates value as ListChar without copying its cells.
Var.listdblExtracts and validates value as ListDbl without copying its cells.
Var.listfloatExtracts and validates value as ListFloat without copying its cells.
Var.listintExtracts and validates value as ListInt without copying its cells.
Var.listshortExtracts and validates value as ListShort without copying its cells.
Var.liststringExtracts and validates value as ListString without copying its cells.
Var.listsymbolExtracts 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:199

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:215

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:211

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:207

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:203

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:219

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:223

ListChar

ListChar.car

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:199

ListChar.cons

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:199

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:199

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:199

ListDbl

ListDbl.car

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:215

ListDbl.cons

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:215

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:215

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:215

ListFloat

ListFloat.car

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:211

ListFloat.cons

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:211

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:211

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:211

ListInt

ListInt.car

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:207

ListInt.cons

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:207

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:207

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:207

ListShort

ListShort.car

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:203

ListShort.cons

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:203

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:203

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:203

ListString

ListString.car

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:219

ListString.cons

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:219

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:219

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:219

ListSymbol

ListSymbol.car

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:223

ListSymbol.cons

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:223

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:223

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:223

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:199

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:215

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:211

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:207

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:203

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:219

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:223

Public types

TypeKindSummary
ListCharaliasTyped view of canonical List cells whose cars are <i8> char values.
ListDblaliasTyped view of canonical List cells whose cars are <f64> double values.
ListFloataliasTyped view of canonical List cells whose cars are <f32> float values.
ListIntaliasTyped view of canonical List cells whose cars are <i32> int values.
ListShortaliasTyped view of canonical List cells whose cars are <i16> short values.
ListStringaliasTyped view of canonical List cells whose cars are <string> Strings.
ListSymbolaliasTyped 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:130

ListDbl

typedef List ListDbl

Typed view of canonical List cells whose cars are <f64> double values.

Source: lib/typed-list.x:141

ListFloat

typedef List ListFloat

Typed view of canonical List cells whose cars are <f32> float values.

Source: lib/typed-list.x:138

ListInt

typedef List ListInt

Typed view of canonical List cells whose cars are <i32> int values.

Source: lib/typed-list.x:135

ListShort

typedef List ListShort

Typed view of canonical List cells whose cars are <i16> short values.

Source: lib/typed-list.x:133

ListString

typedef List ListString

Typed view of canonical List cells whose cars are <string> Strings.

Source: lib/typed-list.x:144

ListSymbol

typedef List ListSymbol

Typed view of canonical List cells whose cars are <symbol> Symbols.

Source: lib/typed-list.x:147

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).