Interface Cons3<O, A, B, C>

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 Cons3<O, A, B, C> {
    arg: A;
    argList: Cons2<A, B, C>;
    base: A;
    end?: number;
    expo: B;
    head: O;
    item0: O;
    item1: A;
    item2: B;
    item3: C;
    lhs: A;
    opr: O;
    pos?: number;
    rhs: B;
    get car(): U;
    get cdr(): Cons;
    get iscons(): boolean;
    get isnil(): boolean;
    get item4(): U;
    get length(): number;
    get name(): "Cons" | "Nil";
    get rest(): Cons;
    [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
  • A extends U
  • B extends U
  • C extends U

Hierarchy (view full)

Properties

arg: A
argList: Cons2<A, B, C>
base: A
end?: number
expo: B
head: O
item0: O
item1: A
item2: B
item3: C
lhs: A
opr: O
pos?: number
rhs: B

Accessors

  • 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 iscons(): boolean
  • Returns boolean

  • get isnil(): boolean
  • Returns boolean

  • get item4(): U
  • Returns U

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

    Returns number

  • 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

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[]