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.

Hierarchy (view full)

Implements

Constructors

  • Parameters

    • car: U
    • cdr: Cons
    • Optional pos: number
    • Optional end: number

    Returns Cons

Properties

end?: number
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 head(): U
  • Exactly the same as the car property. Used for code-as-documentation. The returned item is reference counted.

    Returns U

  • get iscons(): boolean
  • Returns boolean

  • get isnil(): boolean
  • Returns boolean

  • 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 opr(): U
  • A convenience property for the method item(0). A useful shortcut when working with operators. The returned item is reference counted.

    Returns U

  • 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>

  • Parameters

    • needle: U

    Returns boolean

  • Parameters

    • other: U

    Returns boolean

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