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 nonempty xs 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 nonempty xs 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 nonempty xs 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 nonempty xs 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 nonempty xs 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 nonempty xs 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 nonempty xs 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 carry <i8>; another 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:86

List.listdbl

ListDbl List.listdbl(List xs)

Validates xs as ListDbl and returns the identical canonical chain. Nil is valid. Every nonempty cell must carry <f64>; another 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:102

List.listfloat

ListFloat List.listfloat(List xs)

Validates xs as ListFloat and returns the identical canonical chain. Nil is valid. Every nonempty cell must carry <f32>; another 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:98

List.listint

ListInt List.listint(List xs)

Validates xs as ListInt and returns the identical canonical chain. Nil is valid. Every nonempty cell must carry <i32>; another 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:94

List.listshort

ListShort List.listshort(List xs)

Validates xs as ListShort and returns the identical canonical chain. Nil is valid. Every nonempty cell must carry <i16>; another 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:90

List.liststring

ListString List.liststring(List xs)

Validates xs as ListString and returns the identical canonical chain. Nil is valid. Every nonempty cell must carry <string>; another 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:106

List.listsymbol

ListSymbol List.listsymbol(List xs)

Validates xs as ListSymbol and returns the identical canonical chain. Nil is valid. Every nonempty cell must carry <symbol>; another 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:110

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

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

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

ListChar.last

char ListChar.last(ListChar xs)

Returns the final char in nonempty xs after an O(n) walk.

Source: lib/typed-list.x:86

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

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

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

ListDbl.last

double ListDbl.last(ListDbl xs)

Returns the final double in nonempty xs after an O(n) walk.

Source: lib/typed-list.x:102

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

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

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

ListFloat.last

float ListFloat.last(ListFloat xs)

Returns the final float in nonempty xs after an O(n) walk.

Source: lib/typed-list.x:98

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

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

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

ListInt.last

int ListInt.last(ListInt xs)

Returns the final int in nonempty xs after an O(n) walk.

Source: lib/typed-list.x:94

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

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

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

ListShort.last

short ListShort.last(ListShort xs)

Returns the final short in nonempty xs after an O(n) walk.

Source: lib/typed-list.x:90

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

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

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

ListString.last

String ListString.last(ListString xs)

Returns the final String in nonempty xs after an O(n) walk.

Source: lib/typed-list.x:106

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

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

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

ListSymbol.last

Symbol ListSymbol.last(ListSymbol xs)

Returns the final Symbol in nonempty xs after an O(n) walk.

Source: lib/typed-list.x:110

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

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

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

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

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

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

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

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