Interface Cons0<O>

Symbolic expressions are built by connecting Cons structures.

For example, (a * b + c) is built like this:

The car links go downwards, the cdr links go to the right.

      _______      _______                                            _______      _______
|cons |--->|cons |----------------------------------------->|cons |--->|nil |
| | | | | | | |
|_______| |_______| |_______| |_______|
| | |
___v___ ___v___ _______ _______ _______ ___v___
| + | |cons |--->|cons |--->|cons |--->|nil | | c |
| | | | | | | | | | | |
|_______| |_______| |_______| |_______| |_______| |_______|
| | |
___v___ ___v___ ___v___
| * | | a | | b |
| | | | | |
|_______| |_______| |_______|

A nil is a special kind of Cons in which the iscons method returns false. An atom is never in the cdr position. There will be a cons with a nil cdr and a car containing the atom.

interface Cons0<O> {
    end?: number;
    head: O;
    item0: O;
    opr: O;
    pos?: number;
    get arg(): U;
    get argList(): Cons;
    get base(): U;
    get car(): U;
    get cdr(): Cons;
    get expo(): U;
    get iscons(): boolean;
    get isnil(): boolean;
    get item1(): U;
    get item2(): U;
    get item3(): U;
    get item4(): U;
    get length(): number;
    get lhs(): U;
    get name(): "Cons" | "Nil";
    get rest(): Cons;
    get rhs(): U;
    [iterator](): Generator<U, void, unknown>;
    addRef(): void;
    contains(needle): boolean;
    equals(other): boolean;
    item(index): U;
    map(f): Cons;
    release(): void;
    tail(): U[];
    toString(): string;
}

Type Parameters

  • O extends U

Hierarchy (view full)

Properties

end?: number
head: O
item0: O
opr: O
pos?: number

Accessors

  • get arg(): U
  • A convenience property for the method item(1). A useful shortcut when working with unary operators. The returned item is reference counted.

    Returns U

  • get argList(): Cons
  • Exactly the same as the cdr property. Used for code-as-documentation. The returned item is reference counted.

    Returns Cons

  • get base(): U
  • An convenience for cdr.car for use with (power base expo) expressions.

    Returns U

  • get car(): U
  • Returns the car property if it is defined, otherwise nil. The returned item is reference counted.

    Returns U

  • get cdr(): Cons
  • Returns the cdr property if it is defined, otherwise nil. The returned item is reference counted.

    Returns Cons

  • get expo(): U
  • An convenience for cdr.cdr.car for use with (power base expo) expressions.

    Returns U

  • get iscons(): boolean
  • Returns boolean

  • get isnil(): boolean
  • Returns boolean

  • get item1(): U
  • Returns U

  • get item2(): U
  • Returns U

  • get item3(): U
  • Returns U

  • get item4(): U
  • Returns U

  • get length(): number
  • Returns the length of the list.

    Returns number

  • get lhs(): U
  • A convenience property for the method item(1). A useful shortcut when working with binary operators. The returned item is reference counted.

    Returns U

  • get name(): "Cons" | "Nil"
  • Contains the name of the type.

    Returns "Cons" | "Nil"

  • get rest(): Cons
  • Exactly the same as the cdr property. Used for code-as-documentation. The returned item is reference counted.

    Returns Cons

  • get rhs(): U
  • A convenience property for the method item(2). A useful shortcut when working with binary operators. The returned item is reference counted.

    Returns U

Methods

  • Provides an iterator over the Cons, returning the items is the list. The first element returned will be car(cons). The subsequent elements are obtained from walking the cdr's. Hint: Using the ... operator inside [] returns all the items in the list.

    Returns Generator<U, void, unknown>

  • Returns the item at the specified (zero-based) index. The returned item is reference counted.

    (item0 item1 item2 ...)

    Parameters

    • index: number

    Returns U

  • Maps the elements of the list using a mapping function.

    Parameters

    • f: ((a) => U)
        • (a): U
        • Parameters

          Returns U

    Returns Cons

  • Return everything except the first item in the list as a JavaScript array.

    Returns U[]