kei-lisp - v3.0.1
    Preparing search index...

    Class Evaluator

    Class that mimics Lisp's universal function Evaluate.

    Keisuke Ikeda

    Hierarchy

    • Object
      • Evaluator
    Index
    constructor: Function

    The initial value of Object.prototype.constructor is the standard built-in Object constructor.

    depth: number

    The current call depth, used for indenting trace/spy output.

    environment: Table

    The variable binding environment used during evaluation.

    plugins: KeiLispPlugin[]

    Registered plugins consulted by eval when no special form matches.

    streamManager: StreamManager

    The stream manager used for trace and spy output.

    buildInFunctions: Map<InterpretedSymbol, string> = ...

    Lisp-name to method-name dispatch map for special forms.

    macroMarker: InterpretedSymbol = ...

    Marker symbol stored as the car of the Cons that represents a macro binding, distinguishing macros from ordinary lambda closures in the environment.

    • Sequentially evaluates and binds each (symbol value) pair into the given table; used by let*.

      Parameters

      • parameters: Cons

        the Cons of (symbol value) pairs to bind

      • aTable: Table

        the table into which the bindings are written

      Returns null

    • Evaluates all (symbol value) pairs first and then writes them into the given table in parallel; used by let.

      Parameters

      • parameters: Cons

        the Cons of (symbol value) pairs to bind

      • aTable: Table

        the table into which the bindings are written

      Returns null

    • Implementation of the Lisp case special form. Evaluates the key form and runs the body of the first clause whose (unevaluated) keys match the key; a clause head of t or otherwise always matches.

      Parameters

      • aCons: Cons

        the argument Cons containing the key form and the clauses

      Returns LispValue

      the value of the matching clause's last body form, or nil

    • Returns whether a case clause head matches the given key. A head of t or otherwise always matches; a list head matches when any of its (unevaluated) elements is identical to the key; an atom head matches when it is identical to the key. A nil head never matches (CL semantics).

      Parameters

      • key: LispValue

        the evaluated key value

      • head: LispValue

        the clause head (keys), unevaluated

      Returns boolean

      a boolean

    • Implementation of the Lisp catch special form. Evaluates the tag form, then the body; a throw to an eq tag during the body unwinds to here and its value becomes the result.

      Parameters

      • aCons: Cons

        the argument Cons containing the tag form and the body

      Returns LispValue

      the value of the last body form, or the thrown value

    • Parses a lambda source string, captures the current environment, and binds the resulting closure under the given name (used by defstruct).

      Parameters

      • name: string

        the function name to bind

      • source: string

        the lambda source string

      Returns null

    • Implementation of the Lisp defmacro special form. Defines a macro: a transformer whose body receives its arguments unevaluated and returns a form that is then evaluated in the caller's environment.

      Parameters

      • aCons: Cons

        the argument Cons containing the macro name, parameter list, and body

      Returns LispValue

      the macro name symbol

    • Implementation of the Lisp defstruct special form. Defines a structure type represented as a tagged list (name field1 field2 ...) and generates a positional constructor make-<name>, a predicate <name>-p, and one accessor <name>-<field> per field. Accessors are registered as setf places. (Keyword-argument constructors arrive with the keyword type.)

      Parameters

      • aCons: Cons

        the argument Cons containing the struct name and the field symbols

      Returns LispValue

      the struct name symbol

    • Implementation of the Lisp destructuring-bind special form. Binds the symbols of a (possibly nested or dotted) pattern to the corresponding parts of the evaluated expression and evaluates the body.

      Parameters

      • aCons: Cons

        the argument Cons containing the pattern, the expression, and the body

      Returns LispValue

      the value of the last body form

    • Implementation of the Lisp do* special form (sequential binding update).

      Parameters

      • aCons: Cons

        the argument Cons containing bindings, termination clause, and body

      Returns LispValue

      the value of the termination clause's result form

    • Evaluates a procedure call by delegating to the Applier after evaluating each argument.

      Parameters

      • form: Cons

        the call form whose car is the procedure and whose cdr is the argument list

      Returns LispValue

      the result of applying the procedure

    • Evaluates the argument list (the same way entrustApplier does), then delegates the call to the matched plugin with a context that allows recursive evaluation.

      Parameters

      • plugin: KeiLispPlugin

        the plugin that claimed the call symbol

      • form: Cons

        the call form whose car is the symbol and whose cdr is the argument list

      Returns LispValue

      the result returned by the plugin

    • Expands a macro call once and evaluates the resulting form in the current environment.

      Parameters

      • form: Cons

        the call form whose car names the macro

      • macroLambda: Cons

        the macro's transformer lambda Cons

      Returns LispValue

      the result of evaluating the expansion

    • Evaluates a form in tail position. Tail-transparent special forms (if, cond, case, when, unless, progn, let, let*) are unwound iteratively, macros are expanded in place, and a call to a user lambda returns a TailCall sentinel instead of recursing — the Applier's lambda-application loop then applies it iteratively (TCO).

      Parameters

      • form: LispValue

        the form to evaluate in tail position

      Returns LispValue | TailCall

      the evaluation result, or a TailCall sentinel

    • Expands a macro call exactly once by applying its transformer to the unevaluated argument forms in the macro's captured environment.

      Parameters

      • form: Cons

        the call form whose car names the macro

      • macroLambda: Cons

        the macro's transformer lambda Cons

      Returns LispValue

      the expansion form

    • Implementation of the Lisp gc special form; triggers garbage collection and returns memory usage.

      Returns Cons

      an association list of memory usage statistics

    • Implementation of the Lisp handler-case special form (the common subset of CL handler-case / Scheme guard / Clojure try-catch). Evaluates the protected form; when it signals an error, runs the body of the first clause whose type matches — error matches any interpreter error, parse-error / eval-error match the specific families. The clause variable (when given) is bound to the error message string. throw signals and exit are not errors and pass through untouched.

      Parameters

      • aCons: Cons

        the argument Cons containing the protected form and the clauses

      Returns LispValue

      the value of the protected form, or of the matching clause body

    • Determines whether an object has a property with the specified name.

      Parameters

      • v: PropertyKey

        A property name.

      Returns boolean

    • Shared implementation of incf / decf: reads a numeric place, adds the (optional, default 1) delta with the given sign, and writes it back.

      Parameters

      • aCons: Cons

        the argument Cons containing the place and an optional delta form

      • sign: number

        +1 for incf, -1 for decf

      Returns LispValue

      the new value of the place

    • Returns the indentation string used for trace and spy output at the current depth.

      Returns string

      the indentation string

    • Determines whether an object exists in another object's prototype chain.

      Parameters

      • v: Object

        Another object whose prototype chain is to be checked.

      Returns boolean

    • Implementation of the Lisp lambda special form; captures the current environment as a closure. The environment Table is appended after the last body form (the same layout defineDerivedLambda produces), so a body of any length is kept.

      Parameters

      • args: Cons

        the argument Cons containing the parameter list and body

      Returns LispValue

      a lambda form with the captured environment appended

    • Returns the macro transformer (a lambda Cons) bound to the given symbol, or null when the symbol is not bound to a macro. Special-form symbols are never treated as macros.

      Parameters

      • car: LispValue

        the operator position of a call form

      Returns Cons | null

      the macro's lambda Cons, or null

    • Implementation of the Lisp macroexpand special form. Evaluates its argument to obtain a form and repeatedly expands it until the result is no longer a macro call, without evaluating the result.

      Parameters

      • aCons: Cons

        the argument Cons whose car evaluates to the form to expand

      Returns LispValue

      the fully expanded form

    • Implementation of the Lisp macroexpand-1 special form. Evaluates its argument to obtain a form and, when that form is a macro call, expands it exactly once without evaluating the result.

      Parameters

      • aCons: Cons

        the argument Cons whose car evaluates to the form to expand

      Returns LispValue

      the once-expanded form, or the form unchanged when it is not a macro call

    • Returns the cell holding the element at the given 1-based position of a list.

      Parameters

      • list: LispValue

        the list value

      • position: LispValue

        the 1-based position (as used by nth)

      • operator: string

        the operator name used in error messages

      Returns Cons

      the Cons cell whose car is the addressed element

    • Implementation of the Lisp pop special form. Pops the first element off the list stored in a generalized place (CL semantics).

      Parameters

      • aCons: Cons

        the argument Cons whose car is the place bound to a list

      Returns LispValue

      the popped element, or nil if the place value is not a Cons

    • Determines whether a specified property is enumerable.

      Parameters

      • v: PropertyKey

        A property name.

      Returns boolean

    • Implementation of the Lisp push special form. Prepends a value onto the list stored in a generalized place (CL semantics).

      Parameters

      • aCons: Cons

        the argument Cons containing the value to push and the target place

      Returns LispValue

      the new Cons stored in the place

    • Implementation of the Lisp quasiquote (`) special form. Returns the template with every unquote (,) and unquote-splicing (,@) at the matching nesting level replaced by the evaluation of its operand. Nested quasiquotes increase the level so inner unquotes are preserved.

      Parameters

      • aCons: Cons

        the argument Cons whose car is the template

      Returns LispValue

      the constructed form

    • Expands the elements of a quasiquoted list, handling unquote-splicing (,@) elements and a possible dotted unquote (,) tail.

      Parameters

      • template: Cons

        the list template to expand

      • level: number

        the current quasiquote nesting level

      Returns LispValue

      the constructed list

    • Sets the current call depth used for trace and spy indentation.

      Parameters

      • aNumber: number

        the new depth

      Returns null

    • Implementation of the Lisp setf special form. Assigns each value to the corresponding generalized place, like setq but accepting places.

      Parameters

      • args: Cons

        the argument Cons containing alternating (place value) pairs

      Returns LispValue

      the last assigned value

    • Appends the elements of a spliced value (,@) onto the accumulator. The value must be a proper list (or nil); an atom or an improper (dotted) list is rejected rather than silently dropping the dotted tail.

      Parameters

      • parts: LispValue[]

        the accumulator of list elements

      • value: LispValue

        the value produced by an unquote-splicing operand

      Returns null

    • Writes a trace/spy line to the given stream (or stdout) with the current indentation.

      Parameters

      • aStream: string | WritableStream | null

        the destination stream, or null/string to fall back to stdout

      • line: string

        the line to write

      Returns null

    • Evaluates all but the last form of a body and returns the last one as the tail step; an empty body finishes with the given default value.

      Parameters

      Returns
          | { kind: "value"; value: LispValue }
          | { form: LispValue; kind: "form"; table: Table }

      a tail step record or a finished value

    • Walks cond clauses in tail position: evaluates each test and returns the matching clause's last body form as the tail step (or the test value for an empty consequent, matching cond's behavior).

      Parameters

      Returns
          | { kind: "value"; value: LispValue }
          | { form: LispValue; kind: "form"; table: Table }

      a tail step record or a finished value

    • Selects the tail form of a tail-transparent special form, evaluating any non-tail parts (tests, bindings, leading body forms) along the way.

      Parameters

      • formCons: Cons

        the special-form call

      Returns
          | { kind: "value"; value: LispValue }
          | { form: LispValue; kind: "form"; table: Table }
          | null

      a finished value, the next form (with its table) to evaluate in tail position, or null when the operator is not tail-transparent

    • Implementation of the Lisp throw special form. Evaluates the tag and value forms and unwinds to the nearest dynamically enclosing catch whose tag is eq to the thrown tag.

      Parameters

      • aCons: Cons

        the argument Cons containing the tag form and the value form

      Returns never

    • Implementation of the Lisp time special form; measures evaluation time in milliseconds.

      Parameters

      • aCons: Cons

        the argument Cons whose car is the form to time

      Returns number

      the elapsed time in milliseconds

    • Returns a date converted to a string using the current locale.

      Returns string

    • Returns a string representation of an object.

      Returns string

    • Implementation of the Lisp unquote (,) special form. Signals an error because unquote is only meaningful inside a quasiquote template.

      Returns never

    • Implementation of the Lisp unquote-splicing (,@) special form. Signals an error because unquote-splicing is only meaningful inside a quasiquote template.

      Returns never

    • Returns the primitive value of the specified object.

      Returns Object

    • Implementation of the Lisp with-output-to-string special form. Evaluates the body while capturing program output (princ, print, terpri, format) and returns the captured text as a string. The CL stream variable list is accepted for compatibility but no stream is bound (kei-lisp has no stream objects yet), so it must be empty or is ignored.

      Parameters

      • aCons: Cons

        the argument Cons containing an optional stream variable list and the body

      Returns LispValue

      the captured output string

    • Implements (setf (getf plist key) value). When the property list already contains the key its value cell is mutated; otherwise a new (key value) pair is appended. An empty property list is only supported when the plist form is a symbol, which is then rebound to the fresh list.

      Parameters

      • place: Cons

        the (getf plist key) place form

      • value: LispValue

        the value to store

      Returns LispValue

      the stored value

    • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

      Type Parameters

      • T extends {}
      • U

      Parameters

      • target: T

        The target object to copy to.

      • source: U

        The source object from which to copy properties.

      Returns T & U

    • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

      Type Parameters

      • T extends {}
      • U
      • V

      Parameters

      • target: T

        The target object to copy to.

      • source1: U

        The first source object from which to copy properties.

      • source2: V

        The second source object from which to copy properties.

      Returns T & U & V

    • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

      Type Parameters

      • T extends {}
      • U
      • V
      • W

      Parameters

      • target: T

        The target object to copy to.

      • source1: U

        The first source object from which to copy properties.

      • source2: V

        The second source object from which to copy properties.

      • source3: W

        The third source object from which to copy properties.

      Returns T & U & V & W

    • Copy the values of all of the enumerable own properties from one or more source objects to a target object. Returns the target object.

      Parameters

      • target: object

        The target object to copy to.

      • ...sources: any[]

        One or more source objects from which to copy properties

      Returns any

    • Creates an object that has the specified prototype or that has null prototype.

      Parameters

      • o: object | null

        Object to use as a prototype. May be null.

      Returns any

    • Creates an object that has the specified prototype, and that optionally contains specified properties.

      Parameters

      • o: object | null

        Object to use as a prototype. May be null

      • properties: PropertyDescriptorMap & ThisType<any>

        JavaScript object that contains one or more property descriptors.

      Returns any

    • Adds one or more properties to an object, and/or modifies attributes of existing properties.

      Type Parameters

      • T

      Parameters

      • o: T

        Object on which to add or modify the properties. This can be a native JavaScript object or a DOM object.

      • properties: PropertyDescriptorMap & ThisType<any>

        JavaScript object that contains one or more descriptor objects. Each descriptor object describes a data property or an accessor property.

      Returns T

    • Adds a property to an object, or modifies attributes of an existing property.

      Type Parameters

      • T

      Parameters

      • o: T

        Object on which to add or modify the property. This can be a native JavaScript object (that is, a user-defined object or a built in object) or a DOM object.

      • p: PropertyKey

        The property name.

      • attributes: PropertyDescriptor & ThisType<any>

        Descriptor for the property. It can be for a data property or an accessor property.

      Returns T

    • Returns an array of key/values of the enumerable own properties of an object

      Type Parameters

      • T

      Parameters

      • o: { [s: string]: T } | ArrayLike<T>

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns [string, T][]

    • Returns an array of key/values of the enumerable own properties of an object

      Parameters

      • o: {}

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns [string, any][]

    • Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

      Type Parameters

      • T extends Function

      Parameters

      • f: T

        Object on which to lock the attributes.

      Returns T

    • Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

      Type Parameters

      • T extends { [idx: string]: object | U | null | undefined }
      • U extends string | number | bigint | boolean | symbol

      Parameters

      • o: T

        Object on which to lock the attributes.

      Returns Readonly<T>

    • Prevents the modification of existing property attributes and values, and prevents the addition of new properties.

      Type Parameters

      • T

      Parameters

      • o: T

        Object on which to lock the attributes.

      Returns Readonly<T>

    • Returns an object created by key-value entries for properties and methods

      Type Parameters

      • T = any

      Parameters

      • entries: Iterable<readonly [PropertyKey, T]>

        An iterable object that contains key-value entries for properties and methods.

      Returns { [k: string]: T }

    • Returns an object created by key-value entries for properties and methods

      Parameters

      • entries: Iterable<readonly any[]>

        An iterable object that contains key-value entries for properties and methods.

      Returns any

    • Gets the own property descriptor of the specified object. An own property descriptor is one that is defined directly on the object and is not inherited from the object's prototype.

      Parameters

      • o: any

        Object that contains the property.

      • p: PropertyKey

        Name of the property.

      Returns PropertyDescriptor | undefined

    • Returns an object containing all own property descriptors of an object

      Type Parameters

      • T

      Parameters

      • o: T

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns { [P in string | number | symbol]: TypedPropertyDescriptor<T[P]> } & {
          [x: string]: PropertyDescriptor;
      }

    • Returns the names of the own properties of an object. The own properties of an object are those that are defined directly on that object, and are not inherited from the object's prototype. The properties of an object include both fields (objects) and functions.

      Parameters

      • o: any

        Object that contains the own properties.

      Returns string[]

    • Returns an array of all symbol properties found directly on object o.

      Parameters

      • o: any

        Object to retrieve the symbols from.

      Returns symbol[]

    • Returns the prototype of an object.

      Parameters

      • o: any

        The object that references the prototype.

      Returns any

    • Determines whether an object has a property with the specified name.

      Parameters

      • o: object

        An object.

      • v: PropertyKey

        A property name.

      Returns boolean

    • Returns true if the values are the same value, false otherwise.

      Parameters

      • value1: any

        The first value.

      • value2: any

        The second value.

      Returns boolean

    • Returns a value that indicates whether new properties can be added to an object.

      Parameters

      • o: any

        Object to test.

      Returns boolean

    • Returns true if existing property attributes and values cannot be modified in an object, and new properties cannot be added to the object.

      Parameters

      • o: any

        Object to test.

      Returns boolean

    • Returns true if existing property attributes cannot be modified in an object and new properties cannot be added to the object.

      Parameters

      • o: any

        Object to test.

      Returns boolean

    • Returns whether the given value is a user lambda closure (a lambda Cons with a captured environment) rather than a macro or plain data.

      Parameters

      • value: LispValue

        the environment binding to inspect

      Returns boolean

      a boolean

    • Returns the names of the enumerable string properties and methods of an object.

      Parameters

      • o: object

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns string[]

    • Returns the names of the enumerable string properties and methods of an object.

      Parameters

      • o: {}

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns string[]

    • Prevents the addition of new properties to an object.

      Type Parameters

      • T

      Parameters

      • o: T

        Object to make non-extensible.

      Returns T

    • Prevents the modification of attributes of existing properties, and prevents the addition of new properties.

      Type Parameters

      • T

      Parameters

      • o: T

        Object on which to lock the attributes.

      Returns T

    • Sets the prototype of a specified object o to object proto or null. Returns the object o.

      Parameters

      • o: any

        The object to change its prototype.

      • proto: object | null

        The value of the new prototype or null.

      Returns any

    • Returns an array of values of the enumerable own properties of an object

      Type Parameters

      • T

      Parameters

      • o: { [s: string]: T } | ArrayLike<T>

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns T[]

    • Returns an array of values of the enumerable own properties of an object

      Parameters

      • o: {}

        Object that contains the properties and methods. This can be an object that you created or an existing Document Object Model (DOM) object.

      Returns any[]