/** * list.ts: Supporting lists in the Scheme style, using pairs made * up of two-element JavaScript array (vector) * @author: Martin Henz * Translated to TypeScript by Evan Sebastian */ import type { Value } from '../types'; export type Pair = [H, T]; export type List = null | NonEmptyList; export type NonEmptyList = [T, List]; /** * constructs a pair using a two-element array\ * LOW-LEVEL FUNCTION, NOT SOURCE */ export declare function pair(x: T, xs: List): NonEmptyList; export declare function pair(x: H, xs: T): Pair; /** * returns true iff arg is a two-element array\ * LOW-LEVEL FUNCTION, NOT SOURCE */ export declare function is_pair(x: unknown): x is Pair; /** * returns the first component of the given pair\ * LOW-LEVEL FUNCTION, NOT SOURCE * @throws an exception if the argument is not a pair */ export declare function head(xs: Pair | NonEmptyList): T; /** * returns the second component of the given pair\ * LOW-LEVEL FUNCTION, NOT SOURCE * @throws an exception if the argument is not a pair */ export declare function tail(xs: NonEmptyList): List; export declare function tail(xs: Pair): T; /** * changes the head of given pair xs to be x\ * LOW-LEVEL FUNCTION, NOT SOURCE * @throws an exception if the argument is not a pair */ export declare function set_head(xs: Pair, x: any): void; /** * changes the tail of given pair xs to be x\ * LOW-LEVEL FUNCTION, NOT SOURCE * @throws an exception if the argument is not a pair */ export declare function set_tail(xs: Pair, x: any): void; /** * returns true if arg is exactly null\ * LOW-LEVEL FUNCTION, NOT SOURCE */ export declare function is_null(xs: unknown): xs is null; /** * makes a list out of its arguments\ * LOW-LEVEL FUNCTION, NOT SOURCE */ export declare function list(...elements: T[]): NonEmptyList; export declare function list(): List; /** * recurses down the list and checks that it ends with the empty list null\ * LOW-LEVEL FUNCTION, NOT SOURCE */ export declare function is_list(xs: unknown): xs is List; /** * returns vector that contains the elements of the argument list * in the given order.\ * LOW-LEVEL FUNCTION, NOT SOURCE * @throws an exception if the argument is not a list */ export declare function list_to_vector(lst: List): T[]; /** * returns a list that contains the elements of the argument vector * in the given order\ * LOW-LEVEL FUNCTION, NOT SOURCE * @throws an exception if the argument is not a vector */ export declare function vector_to_list(vector: T[]): List; /** * Accumulate applies given operation op to elements of a list * in a right-to-left order, first apply op to the last element * and an initial element, resulting in r1, then to the second-last * element and r1, resulting in r2, etc, and finally to the first element * and r_n-1, where n is the length of the list. `accumulate(op,zero,list(1,2,3))` * results in `op(1, op(2, op(3, zero)))` */ export declare function accumulate(op: (each: T, result: U) => U, initial: U, sequence: List): U; /** * Appends the list `ys` to the end of list `xs` and returns the * resulting list */ export declare function append(xs: List, ys: List): List; /** * Takes a unary function `f` and a non-negative integer `n`. Returns the list * of `n` elements that results from applying `f` to the numbers from 0 to `n-1`. */ export declare function build_list(f: (arg: number) => T, n: number): List; /** * Takes two numbers, `start` and `end` and returns the list containing numbers between `start` and `end`, * beginning with `start` and then incrementing by 1 until the value exceeds `end`. */ export declare function enum_list(start: number, end: number): List; /** * Returns a new list that only contains elements that the predicate function returned `true` * for */ export declare function filter(pred: (arg: T) => arg is U, xs: List): List; export declare function filter(pred: (arg: T) => boolean, xs: List): List; /** * Applies the provided function to each element in the list. Returns `true`. */ export declare function for_each(op: (arg: T) => void, xs: List): true; /** * returns the length of a List xs. Throws an exception if xs is not a List */ export declare function length(xs: unknown): number; /** * Returns the element at the `n`th index in the provided list */ export declare function list_ref(xs: List, n: number): T; /** * Calls the provided function on each element of the provided list, and returns * a new list containing the results */ export declare function map(op: (each: T) => U, sequence: List): List; /** * Returns the first postfix sublist that starts with the given element `v`. If * the element is not in `xs`, returns an empty list. */ export declare function member(v: T, xs: List): List; /** * Removes the first instance of `v` in the given List `xs`. */ export declare function remove(v: T, xs: List): List; /** * Removes all instances of `v` from the given list `xs`. */ export declare function remove_all(v: T, xs: List): List; /** * Reverses the given list `xs`. */ export declare function reverse(xs: List): List; export declare function rawDisplayList(display: (v: Value, ...s: string[]) => Value, xs: Value, prepend: string): any;