kei-lisp 2.1.0 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -20,48 +20,70 @@ type LispValue = Cons | InterpretedSymbol | Table | number | string | null;
20
20
  * @this {Table}
21
21
  */
22
22
  declare class Table extends Map<unknown, LispValue> {
23
+ /**
24
+ * The enclosing (parent) environment, or null when this is the root.
25
+ */
23
26
  source: Table | null;
27
+ /**
28
+ * Whether this environment is the root of its chain.
29
+ */
24
30
  root: boolean;
25
31
  /**
26
32
  * Constructor.
33
+ * @constructor
27
34
  * @param aTable the environment in which this environment was created
28
35
  */
29
36
  constructor(aTable?: Table | null);
30
37
  /**
31
38
  * Clones this Table and returns the clone.
39
+ * @return the cloned Table
32
40
  */
33
41
  clone(): Table;
34
42
  /**
35
43
  * Returns whether anything is bound to the given property (key).
44
+ * @param aSymbol the symbol to look up
45
+ * @return true if a binding exists in this scope or any enclosing scope
36
46
  */
37
47
  has(aSymbol: unknown): boolean;
38
48
  /**
39
49
  * Returns whether this instance equals the given object.
50
+ * @param anObject the object to compare against
51
+ * @return true when the underlying Map.equals would return true
40
52
  */
41
53
  equals(anObject: unknown): boolean;
42
54
  /**
43
- * Returns the value bound to the given interpreted symbol.
55
+ * Returns the value bound to the given interpreted symbol, walking up the scope chain.
56
+ * @param aSymbol the symbol to look up
57
+ * @return the bound value, or null when no binding exists
44
58
  */
45
59
  get(aSymbol: unknown): LispValue;
46
60
  /**
47
61
  * Returns whether this instance is the root of the environment chain.
62
+ * @return true if this is the root environment
48
63
  */
49
64
  isRoot(): boolean;
50
65
  /**
51
- * Reassigns the symbol bound in the innermost scope (equivalent to Common Lisp's setq).
52
- * If a binding exists in the current scope, update it and return; otherwise recurse into the parent scope.
66
+ * Reassigns the symbol bound in the innermost scope (equivalent to Common Lisp's setq). If a binding exists in the current scope, update it and return; otherwise recurse into the parent scope.
67
+ * @param aSymbol the symbol to update
68
+ * @param anObject the new bound value
69
+ * @return the new bound value, or null when no enclosing scope has a binding
53
70
  */
54
71
  setIfExist(aSymbol: unknown, anObject: LispValue): LispValue;
55
72
  /**
56
73
  * Sets whether this instance is the root of its environment chain.
74
+ * @param aBoolean the new root flag
75
+ * @return null
57
76
  */
58
77
  setRoot(aBoolean: boolean): null;
59
78
  /**
60
79
  * Sets the parent environment.
80
+ * @param aTable the new parent environment (or null)
81
+ * @return null
61
82
  */
62
83
  setSource(aTable: Table | null): null;
63
84
  /**
64
85
  * Returns a formatted string representation of this instance.
86
+ * @return the formatted string
65
87
  */
66
88
  toString(): string;
67
89
  }
@@ -73,12 +95,20 @@ declare class Table extends Map<unknown, LispValue> {
73
95
  * @author Keisuke Ikeda
74
96
  * @this {InterpretedSymbol}
75
97
  */
76
- declare class InterpretedSymbol {
98
+ declare class InterpretedSymbol extends Object {
77
99
  #private;
100
+ /**
101
+ * Lazy accessor for the intern table that holds every InterpretedSymbol instance.
102
+ * @return the intern Table (created on first access)
103
+ */
78
104
  static get table(): Table;
105
+ /**
106
+ * The printed name of this symbol.
107
+ */
79
108
  name: string;
80
109
  /**
81
110
  * Constructor.
111
+ * @constructor
82
112
  * @param name printed name
83
113
  */
84
114
  constructor(name?: string);
@@ -90,15 +120,19 @@ declare class InterpretedSymbol {
90
120
  compareTo(aSymbol: InterpretedSymbol): number;
91
121
  /**
92
122
  * Returns whether this symbol equals the given object.
123
+ * @param anObject the object to compare against
124
+ * @return true when identity-equal (since intern guarantees uniqueness)
93
125
  */
94
126
  equals(anObject: unknown): boolean;
95
127
  /**
96
128
  * Returns the same interpreted symbol for a given printed name.
97
129
  * @param aString printed name
130
+ * @return the canonical InterpretedSymbol for that name
98
131
  */
99
132
  static of(aString: string): InterpretedSymbol;
100
133
  /**
101
134
  * Returns the string representation of this symbol.
135
+ * @return the printed name
102
136
  */
103
137
  toString(): string;
104
138
  }
@@ -110,39 +144,53 @@ declare class InterpretedSymbol {
110
144
  * @author Keisuke Ikeda
111
145
  * @this {Loop}
112
146
  */
113
- declare class Loop {
147
+ declare class Loop extends Object {
148
+ /**
149
+ * The Cons being iterated over.
150
+ */
114
151
  aCons: Cons;
152
+ /**
153
+ * The number of elements in the underlying Cons (computed once at construction time).
154
+ */
115
155
  length: number;
156
+ /**
157
+ * The 1-based index of the next element to return.
158
+ */
116
159
  index: number;
117
160
  /**
118
161
  * Constructor.
162
+ * @constructor
119
163
  * @param aCons the Cons to iterate over
120
164
  */
121
165
  constructor(aCons: Cons);
122
166
  /**
123
- * Returns this instance.
167
+ * Returns this instance so it can be used as its own iterator.
168
+ * @return this Loop instance
124
169
  */
125
170
  iterator(): this;
126
171
  /**
127
172
  * Returns whether a next element exists.
173
+ * @return true if there is at least one more element
128
174
  */
129
175
  hasNext(): boolean;
130
176
  /**
131
- * Returns the next element.
177
+ * Returns the next element and advances the cursor.
178
+ * @return the element at the current index
132
179
  */
133
180
  next(): LispValue;
134
181
  /**
135
- * Implementation of the iterable protocol.
136
- * Enables iteration with for...of and similar constructs.
182
+ * Implementation of the iterable protocol. Enables iteration with for...of and similar constructs.
183
+ * @return an iterator over the Cons elements
137
184
  */
138
185
  [Symbol.iterator](): Iterator<LispValue>;
139
186
  /**
140
- * Implementation of the async iterable protocol.
141
- * Enables iteration with for await...of and similar constructs.
187
+ * Implementation of the async iterable protocol. Enables iteration with for await...of and similar constructs.
188
+ * @return an async iterator over the Cons elements
142
189
  */
143
190
  [Symbol.asyncIterator](): AsyncIterator<LispValue>;
144
191
  /**
145
- * Advances to the next element.
192
+ * Advances the cursor to the next element.
193
+ * @return null
146
194
  */
147
195
  remove(): null;
148
196
  }
@@ -154,9 +202,18 @@ declare class Loop {
154
202
  * @author Keisuke Ikeda
155
203
  * @this {Cons}
156
204
  */
157
- declare class Cons {
205
+ declare class Cons extends Object {
206
+ /**
207
+ * The shared empty-list sentinel. A Cons whose car and cdr are both itself, representing Lisp `nil`.
208
+ */
158
209
  static readonly nil: Cons;
210
+ /**
211
+ * The head element of this Cons cell.
212
+ */
159
213
  car: LispValue;
214
+ /**
215
+ * The tail of this Cons cell (typically another Cons or nil).
216
+ */
160
217
  cdr: LispValue;
161
218
  /**
162
219
  * Constructor.
@@ -302,32 +359,153 @@ declare class Cons {
302
359
  type Stream = NodeJS.WritableStream | null;
303
360
  /**
304
361
  * @class
305
- * @classdesc
362
+ * @classdesc Manages output streams (stdout / stderr / spy / trace) used by the interpreter.
306
363
  * @author Keisuke Ikeda
307
364
  * @this {StreamManager}
308
365
  */
309
- declare class StreamManager {
366
+ declare class StreamManager extends Object {
367
+ /**
368
+ * Whether tracing is currently enabled.
369
+ */
310
370
  isTrace: boolean;
371
+ /**
372
+ * Map from a named stream key (e.g. "default", "stdout", "stderr") to a WritableStream.
373
+ */
311
374
  streamTable: Map<string, Stream>;
375
+ /**
376
+ * Map from a spied symbol to the stream key used for that symbol's output.
377
+ */
312
378
  spyTable: Map<InterpretedSymbol, string>;
379
+ /**
380
+ * The stream that receives trace output while tracing is on.
381
+ */
313
382
  traceStream: Stream;
383
+ /**
384
+ * Constructor.
385
+ * @constructor
386
+ */
314
387
  constructor();
388
+ /**
389
+ * Returns the currently selected output stream (trace stream when tracing, otherwise the default).
390
+ * @return the active stream, or null when none is available
391
+ */
315
392
  getStream(): Stream;
316
393
  /**
317
394
  * Initializes the instance variables.
395
+ * @return null
318
396
  */
319
397
  initialize(): null;
398
+ /**
399
+ * Returns whether the given symbol is being spied (or whether tracing is on, in which case every symbol is "spied").
400
+ * @param aSymbol the symbol to check, or null
401
+ * @return true if the symbol is spied or tracing is on
402
+ */
320
403
  isSpy(aSymbol: InterpretedSymbol | null): boolean;
404
+ /**
405
+ * Removes the given symbol from the spy table.
406
+ * @param aSymbol the symbol to stop spying
407
+ * @return null
408
+ */
321
409
  noSpy(aSymbol: InterpretedSymbol): null;
410
+ /**
411
+ * Turns tracing off and clears the spy table.
412
+ * @return null
413
+ */
322
414
  noTrace(): null;
415
+ /**
416
+ * Sets the tracing flag.
417
+ * @param aBoolean the new value for the tracing flag
418
+ * @return null
419
+ */
323
420
  setIsTrace(aBoolean: boolean): null;
421
+ /**
422
+ * Sets the trace output stream.
423
+ * @param aStream the stream to send trace output to
424
+ * @return null
425
+ */
324
426
  setTraceStream(aStream: Stream): null;
427
+ /**
428
+ * Registers the given symbol as spied with the given stream key.
429
+ * @param aSymbol the symbol to spy on
430
+ * @param aString the stream key (e.g. "default")
431
+ * @return null
432
+ */
325
433
  spy(aSymbol: InterpretedSymbol, aString: string): null;
434
+ /**
435
+ * Returns the stream (or stream-key string) used for the given symbol's spy output.
436
+ * @param aSymbol the symbol whose spy stream is requested, or null
437
+ * @return the trace stream, the registered key string, or throws if none is found
438
+ */
326
439
  spyStream(aSymbol: InterpretedSymbol | null): Stream | string;
440
+ /**
441
+ * Returns a copy of the spy table (defensive copy so callers do not mutate the internal map).
442
+ * @return a new map containing the same entries as the internal spy table
443
+ */
327
444
  spyTable_(): Map<InterpretedSymbol, string>;
445
+ /**
446
+ * Turns tracing on, routing trace output to the currently active stream.
447
+ * @return null
448
+ */
328
449
  trace(): null;
329
450
  }
330
451
  //#endregion
452
+ //#region src/plugin/types.d.ts
453
+ /**
454
+ * Context passed to a plugin's `apply` call. Holds the live interpreter state
455
+ * needed to perform recursive evaluation or to read / write the environment.
456
+ */
457
+ interface PluginContext {
458
+ /**
459
+ * The current variable binding environment.
460
+ */
461
+ environment: Table;
462
+ /**
463
+ * The stream manager that owns the interpreter's I/O / spy / trace streams.
464
+ */
465
+ streamManager: StreamManager;
466
+ /**
467
+ * The current call depth (used for spy indentation).
468
+ */
469
+ depth: number;
470
+ /**
471
+ * Re-evaluates the given form using the current environment / stream manager / depth.
472
+ * Use this to evaluate a sub-form (e.g. when the plugin received a lambda value).
473
+ * @param form the form to evaluate
474
+ * @return the evaluation result
475
+ */
476
+ eval(form: LispValue): LispValue;
477
+ }
478
+ /**
479
+ * A kei-lisp plugin contributes additional Lisp-callable functions to the
480
+ * interpreter. Register one with `LispInterpreter.use(plugin)`. When the
481
+ * evaluator encounters `(symbol ...)` and `symbol` is not a special form,
482
+ * registered plugins are consulted in registration order; the first plugin
483
+ * whose `has(symbol)` returns true handles the call.
484
+ *
485
+ * Arguments are pre-evaluated by the interpreter before being passed to
486
+ * `apply`, matching the calling convention of built-in functions.
487
+ */
488
+ interface KeiLispPlugin {
489
+ /**
490
+ * Plugin identifier, used for diagnostics and collision messages.
491
+ */
492
+ readonly name: string;
493
+ /**
494
+ * Returns true if this plugin handles the given symbol.
495
+ * @param symbol the call symbol to check
496
+ * @return true if `apply` should be called for this symbol
497
+ */
498
+ has(symbol: InterpretedSymbol): boolean;
499
+ /**
500
+ * Applies the plugin function to the (already-evaluated) arguments.
501
+ * @param symbol the call symbol
502
+ * @param args the evaluated argument list (a Cons, possibly Cons.nil)
503
+ * @param ctx the interpreter context for recursive evaluation
504
+ * @return the result value
505
+ */
506
+ apply(symbol: InterpretedSymbol, args: Cons, ctx: PluginContext): LispValue;
507
+ }
508
+ //#endregion
331
509
  //#region src/interpreter/LispInterpreter/index.d.ts
332
510
  /**
333
511
  * @class
@@ -335,22 +513,50 @@ declare class StreamManager {
335
513
  * @author Keisuke Ikeda
336
514
  * @this {LispInterpreter}
337
515
  */
338
- declare class LispInterpreter {
516
+ declare class LispInterpreter extends Object {
517
+ /**
518
+ * The root (top-level) environment table, pre-populated with built-in symbols.
519
+ */
339
520
  root: Table;
521
+ /**
522
+ * The stream manager that owns the interpreter's output / spy streams.
523
+ */
340
524
  streamManager: StreamManager;
525
+ /**
526
+ * Registered plugins consulted by the evaluator on every call. See `use`.
527
+ */
528
+ plugins: KeiLispPlugin[];
529
+ /**
530
+ * Constructor.
531
+ * @constructor
532
+ */
341
533
  constructor();
534
+ /**
535
+ * Registers a plugin. Subsequent `eval` calls will consult the plugin chain
536
+ * (in registration order, first match wins) when no special form matches a
537
+ * symbol, before falling through to the Applier built-ins.
538
+ * @param plugin the plugin to register
539
+ * @return this interpreter, for chaining
540
+ */
541
+ use(plugin: KeiLispPlugin): this;
342
542
  /**
343
543
  * Evaluates the given expression and returns the result. Throws `ParseError`,
344
544
  * `EvalError`, or `ExitError` on failure; library users are expected to catch
345
545
  * these (see the `KeiLispError` base class for the parse/eval family).
546
+ * @param aCons the expression to evaluate
547
+ * @return the evaluation result
346
548
  */
347
549
  eval(aCons: LispValue): LispValue;
348
550
  /**
349
551
  * Parses the source string, evaluates every expression it contains, and returns the results as an array.
552
+ * @param source the Lisp source string
553
+ * @return the array of evaluation results, one per top-level expression
350
554
  */
351
555
  evalAll(source: string): LispValue[];
352
556
  /**
353
557
  * Parses and evaluates the source string and returns the value of the last expression.
558
+ * @param source the Lisp source string
559
+ * @return the value of the last expression, or `Cons.nil` for empty input
354
560
  */
355
561
  evalString(source: string): LispValue;
356
562
  /**
@@ -358,14 +564,19 @@ declare class LispInterpreter {
358
564
  * it. The result is always a `Cons` (possibly `Cons.nil` for empty input)
359
565
  * because the source is wrapped in an outer list before parsing. Throws
360
566
  * `ParseError` if the source cannot be parsed.
567
+ * @param aString the Lisp source string
568
+ * @return a Cons containing the parsed top-level expressions
361
569
  */
362
570
  parse(aString: string): Cons;
363
571
  /**
364
572
  * Sets the given environment as the root of the environment chain.
573
+ * @param environment the environment table to install as root
574
+ * @return null
365
575
  */
366
576
  setRoot(environment: Table): null;
367
577
  /**
368
- * Initializes the environment table.
578
+ * Builds the root environment table by pre-registering every built-in symbol and the small set of bootstrap lambdas (append / butlast / nthcdr / reverse).
579
+ * @return the freshly initialized root environment
369
580
  */
370
581
  initializeTable(): Table;
371
582
  }
@@ -377,16 +588,442 @@ declare class LispInterpreter {
377
588
  * @author Keisuke Ikeda
378
589
  * @this {Repl}
379
590
  */
380
- declare class Repl {
591
+ declare class Repl extends Object {
592
+ /**
593
+ * The underlying interpreter used to parse and evaluate user input.
594
+ */
381
595
  interpreter: LispInterpreter;
596
+ /**
597
+ * The Node.js readline interface that supplies prompt I/O.
598
+ */
382
599
  rl: Interface;
600
+ /**
601
+ * Constructor.
602
+ * @constructor
603
+ * @param interpreter the interpreter to evaluate input against (defaults to a fresh one)
604
+ */
383
605
  constructor(interpreter?: LispInterpreter);
384
606
  /**
385
607
  * Starts the REPL loop.
608
+ * @return void
386
609
  */
387
610
  run(): void;
388
611
  }
389
612
  //#endregion
613
+ //#region src/runtime/Evaluator/index.d.ts
614
+ /**
615
+ * @class
616
+ * @classdesc Class that mimics Lisp's universal function Evaluate.
617
+ * @author Keisuke Ikeda
618
+ * @this {Evaluator}
619
+ */
620
+ declare class Evaluator extends Object {
621
+ /**
622
+ * Lisp-name to method-name dispatch map for special forms.
623
+ */
624
+ static readonly buildInFunctions: Map<InterpretedSymbol, string>;
625
+ /**
626
+ * Marker symbol stored as the car of the Cons that represents a macro binding,
627
+ * distinguishing macros from ordinary `lambda` closures in the environment.
628
+ */
629
+ static readonly macroMarker: InterpretedSymbol;
630
+ /**
631
+ * The variable binding environment used during evaluation.
632
+ */
633
+ environment: Table;
634
+ /**
635
+ * The stream manager used for trace and spy output.
636
+ */
637
+ streamManager: StreamManager;
638
+ /**
639
+ * The current call depth, used for indenting trace/spy output.
640
+ */
641
+ depth: number;
642
+ /**
643
+ * Registered plugins consulted by `eval` when no special form matches.
644
+ */
645
+ plugins: KeiLispPlugin[];
646
+ /**
647
+ * Constructor.
648
+ * @param aTable the variable binding environment
649
+ * @param aStreamManager the stream manager for trace and spy output
650
+ * @param aNumber the initial call depth
651
+ * @param plugins the plugin chain consulted before falling through to Applier
652
+ */
653
+ constructor(aTable: Table, aStreamManager: StreamManager, aNumber: number, plugins?: KeiLispPlugin[]);
654
+ /**
655
+ * Implementation of the Lisp `and` special form.
656
+ * @param aCons the argument Cons containing the expressions to evaluate
657
+ * @return nil if any expression evaluates to nil, otherwise t
658
+ */
659
+ and(aCons: Cons): LispValue;
660
+ /**
661
+ * Implementation of the Lisp `apply` special form.
662
+ * @param aCons the argument Cons containing the procedure and its argument list
663
+ * @return the result of applying the procedure to the arguments
664
+ */
665
+ apply_lisp(aCons: Cons): LispValue;
666
+ /**
667
+ * Implementation of the Lisp `bind` special form.
668
+ * @param aCons the argument Cons whose car is the symbol to look up
669
+ * @return the binding count for the symbol, or nil if unbound
670
+ */
671
+ bind(aCons: Cons): LispValue;
672
+ /**
673
+ * Counts the number of distinct bindings for the given symbol along the environment chain.
674
+ * @param aSymbol the symbol whose bindings are inspected
675
+ * @return the number of distinct bindings found
676
+ */
677
+ bindAUX(aSymbol: InterpretedSymbol): number;
678
+ /**
679
+ * Sequentially evaluates and binds each (symbol value) pair into the given table; used by let*.
680
+ * @param parameters the Cons of (symbol value) pairs to bind
681
+ * @param aTable the table into which the bindings are written
682
+ */
683
+ binding(parameters: Cons, aTable: Table): null;
684
+ /**
685
+ * Evaluates all (symbol value) pairs first and then writes them into the given table in parallel; used by let.
686
+ * @param parameters the Cons of (symbol value) pairs to bind
687
+ * @param aTable the table into which the bindings are written
688
+ */
689
+ bindingParallel(parameters: Cons, aTable: Table): null;
690
+ /**
691
+ * Implementation of the Lisp `cond` special form.
692
+ * @param aCons the argument Cons of (test consequent...) clauses
693
+ * @return the result of the first clause whose test is non-nil, or nil
694
+ */
695
+ cond(aCons: LispValue): LispValue;
696
+ /**
697
+ * Implementation of the Lisp `defun` special form.
698
+ * @param aCons the argument Cons containing the function name, parameter list, and body
699
+ * @return the function name symbol
700
+ */
701
+ defun(aCons: Cons): LispValue;
702
+ /**
703
+ * Implementation of the Lisp `defmacro` special form. Defines a macro: a
704
+ * transformer whose body receives its arguments unevaluated and returns a
705
+ * form that is then evaluated in the caller's environment.
706
+ * @param aCons the argument Cons containing the macro name, parameter list, and body
707
+ * @return the macro name symbol
708
+ */
709
+ defmacro(aCons: Cons): LispValue;
710
+ /**
711
+ * Returns the macro transformer (a lambda Cons) bound to the given symbol, or
712
+ * null when the symbol is not bound to a macro. Special-form symbols are never
713
+ * treated as macros.
714
+ * @param car the operator position of a call form
715
+ * @return the macro's lambda Cons, or null
716
+ */
717
+ lookupMacro(car: LispValue): Cons | null;
718
+ /**
719
+ * Expands a macro call exactly once by applying its transformer to the
720
+ * unevaluated argument forms in the macro's captured environment.
721
+ * @param form the call form whose car names the macro
722
+ * @param macroLambda the macro's transformer lambda Cons
723
+ * @return the expansion form
724
+ */
725
+ expandMacro1(form: Cons, macroLambda: Cons): LispValue;
726
+ /**
727
+ * Expands a macro call once and evaluates the resulting form in the current
728
+ * environment.
729
+ * @param form the call form whose car names the macro
730
+ * @param macroLambda the macro's transformer lambda Cons
731
+ * @return the result of evaluating the expansion
732
+ */
733
+ evalMacroCall(form: Cons, macroLambda: Cons): LispValue;
734
+ /**
735
+ * Implementation of the Lisp `macroexpand-1` special form. Evaluates its
736
+ * argument to obtain a form and, when that form is a macro call, expands it
737
+ * exactly once without evaluating the result.
738
+ * @param aCons the argument Cons whose car evaluates to the form to expand
739
+ * @return the once-expanded form, or the form unchanged when it is not a macro call
740
+ */
741
+ macroexpand_1(aCons: Cons): LispValue;
742
+ /**
743
+ * Implementation of the Lisp `macroexpand` special form. Evaluates its
744
+ * argument to obtain a form and repeatedly expands it until the result is no
745
+ * longer a macro call, without evaluating the result.
746
+ * @param aCons the argument Cons whose car evaluates to the form to expand
747
+ * @return the fully expanded form
748
+ */
749
+ macroexpand(aCons: Cons): LispValue;
750
+ /**
751
+ * Implementation of the Lisp `do` special form (parallel binding update).
752
+ * @param aCons the argument Cons containing bindings, termination clause, and body
753
+ * @return the value of the termination clause's result form
754
+ */
755
+ do_(aCons: Cons): LispValue;
756
+ /**
757
+ * Implementation of the Lisp `dolist` special form.
758
+ * @param aCons the argument Cons containing the binding clause and body
759
+ * @return the value of the result form
760
+ */
761
+ doList(aCons: Cons): LispValue;
762
+ /**
763
+ * Implementation of the Lisp `do*` special form (sequential binding update).
764
+ * @param aCons the argument Cons containing bindings, termination clause, and body
765
+ * @return the value of the termination clause's result form
766
+ */
767
+ doStar(aCons: Cons): LispValue;
768
+ /**
769
+ * Evaluates a procedure call by delegating to the Applier after evaluating each argument.
770
+ * @param form the call form whose car is the procedure and whose cdr is the argument list
771
+ * @return the result of applying the procedure
772
+ */
773
+ entrustApplier(form: Cons): LispValue;
774
+ /**
775
+ * Evaluates the given form in the given environment.
776
+ * @param form the form to evaluate
777
+ * @param environment the variable binding environment
778
+ * @param aStreamManager the stream manager for trace and spy output
779
+ * @param depth the current call depth
780
+ * @param plugins the plugin chain consulted before falling through to Applier
781
+ * @return the evaluation result
782
+ */
783
+ static eval(form: LispValue, environment: Table, aStreamManager?: StreamManager, depth?: number, plugins?: KeiLispPlugin[]): LispValue;
784
+ /**
785
+ * Evaluates the given form using this Evaluator's environment.
786
+ * @param form the form to evaluate
787
+ * @return the evaluation result
788
+ */
789
+ eval(form: LispValue): LispValue;
790
+ /**
791
+ * Evaluates the argument list (the same way `entrustApplier` does), then
792
+ * delegates the call to the matched plugin with a context that allows
793
+ * recursive evaluation.
794
+ * @param plugin the plugin that claimed the call symbol
795
+ * @param form the call form whose car is the symbol and whose cdr is the argument list
796
+ * @return the result returned by the plugin
797
+ */
798
+ entrustPlugin(plugin: KeiLispPlugin, form: Cons): LispValue;
799
+ /**
800
+ * Implementation of the Lisp `eval` special form.
801
+ * @param aCons the argument Cons whose car is the form to evaluate twice
802
+ * @return the result of evaluating the form
803
+ */
804
+ eval_lisp(aCons: Cons): LispValue;
805
+ /**
806
+ * Resolves the value bound to the given symbol in the current environment.
807
+ * @param aSymbol the symbol to resolve
808
+ * @return the value bound to the symbol
809
+ */
810
+ evaluateSymbol(aSymbol: InterpretedSymbol): LispValue;
811
+ /**
812
+ * Implementation of the Lisp `exit` special form; terminates the REPL by throwing an ExitError.
813
+ */
814
+ exit(): never;
815
+ /**
816
+ * Implementation of the Lisp `gc` special form; triggers garbage collection and returns memory usage.
817
+ * @return an association list of memory usage statistics
818
+ */
819
+ gc(): Cons;
820
+ /**
821
+ * Implementation of the Lisp `if` special form.
822
+ * @param aCons the argument Cons containing the test, then-form, and else-form
823
+ * @return the result of evaluating the selected branch
824
+ */
825
+ if_(aCons: Cons): LispValue;
826
+ /**
827
+ * Returns the indentation string used for trace and spy output at the current depth.
828
+ * @return the indentation string
829
+ */
830
+ indent(): string;
831
+ /**
832
+ * Returns whether the given symbol is currently being spied on.
833
+ * @param aSymbol the symbol to check
834
+ * @return a boolean
835
+ */
836
+ isSpy(aSymbol: InterpretedSymbol | null): boolean;
837
+ /**
838
+ * Implementation of the Lisp `lambda` special form; captures the current environment as a closure.
839
+ * @param args the argument Cons containing the parameter list and body
840
+ * @return a lambda form with the captured environment appended
841
+ */
842
+ lambda(args: Cons): LispValue;
843
+ /**
844
+ * Implementation of the Lisp `let` special form (parallel binding).
845
+ * @param aCons the argument Cons containing bindings and body
846
+ * @return the value of the last body form
847
+ */
848
+ let(aCons: Cons): LispValue;
849
+ /**
850
+ * Implementation of the Lisp `let*` special form (sequential binding).
851
+ * @param aCons the argument Cons containing bindings and body
852
+ * @return the value of the last body form
853
+ */
854
+ letStar(aCons: Cons): LispValue;
855
+ /**
856
+ * Implementation of the Lisp `not` special form.
857
+ * @param aCons the argument Cons whose car is the expression to negate
858
+ * @return t if the expression evaluates to nil, otherwise nil
859
+ */
860
+ not(aCons: Cons): LispValue;
861
+ /**
862
+ * Implementation of the Lisp `notrace` special form; disables tracing.
863
+ * @return the symbol t
864
+ */
865
+ notrace(): InterpretedSymbol;
866
+ /**
867
+ * Implementation of the Lisp `or` special form.
868
+ * @param aCons the argument Cons containing the expressions to evaluate
869
+ * @return t if any expression evaluates to non-nil, otherwise nil
870
+ */
871
+ or(aCons: Cons): LispValue;
872
+ /**
873
+ * Implementation of the Lisp `pop` special form.
874
+ * @param aCons the argument Cons whose car is the symbol bound to a list
875
+ * @return the popped element, or nil if the binding is not a Cons
876
+ */
877
+ pop_(aCons: Cons): LispValue;
878
+ /**
879
+ * Implementation of the Lisp `progn` special form.
880
+ * @param aCons the argument Cons containing the body expressions
881
+ * @return the value of the last body form, or nil if there are none
882
+ */
883
+ progn(aCons: Cons): LispValue;
884
+ /**
885
+ * Implementation of the Lisp `princ` special form; writes the evaluated argument without a trailing newline.
886
+ * @param aCons the argument Cons whose car is the expression to print
887
+ * @return the printed value
888
+ */
889
+ princ(aCons: Cons): LispValue;
890
+ /**
891
+ * Implementation of the Lisp `print` special form; writes the evaluated argument followed by a newline.
892
+ * @param aCons the argument Cons whose car is the expression to print
893
+ * @return the printed value
894
+ */
895
+ print(aCons: Cons): LispValue;
896
+ /**
897
+ * Implementation of the Lisp `push` special form.
898
+ * @param aCons the argument Cons containing the value to push and the target symbol
899
+ * @return the new Cons stored in the symbol
900
+ */
901
+ push_(aCons: Cons): LispValue;
902
+ /**
903
+ * Implementation of the Lisp `quote` special form.
904
+ * @param aCons the argument Cons whose car is the form to return unevaluated
905
+ * @return the quoted form
906
+ */
907
+ quote(aCons: Cons): LispValue;
908
+ /**
909
+ * Implementation of the Lisp `quasiquote` (`` ` ``) special form. Returns the
910
+ * template with every `unquote` (`,`) and `unquote-splicing` (`,@`) at the
911
+ * matching nesting level replaced by the evaluation of its operand. Nested
912
+ * quasiquotes increase the level so inner unquotes are preserved.
913
+ * @param aCons the argument Cons whose car is the template
914
+ * @return the constructed form
915
+ */
916
+ quasiquote(aCons: Cons): LispValue;
917
+ /**
918
+ * Recursively expands a quasiquote template at the given nesting level.
919
+ * @param template the template to expand
920
+ * @param level the current quasiquote nesting level (1 is the outermost)
921
+ * @return the expanded value
922
+ */
923
+ quasiquoteExpand(template: LispValue, level: number): LispValue;
924
+ /**
925
+ * Expands the elements of a quasiquoted list, handling `unquote-splicing`
926
+ * (`,@`) elements and a possible dotted `unquote` (`,`) tail.
927
+ * @param template the list template to expand
928
+ * @param level the current quasiquote nesting level
929
+ * @return the constructed list
930
+ */
931
+ quasiquoteList(template: Cons, level: number): LispValue;
932
+ /**
933
+ * Appends the elements of a spliced value (`,@`) onto the accumulator. The
934
+ * value must be a proper list (or nil); an atom or an improper (dotted) list
935
+ * is rejected rather than silently dropping the dotted tail.
936
+ * @param parts the accumulator of list elements
937
+ * @param value the value produced by an `unquote-splicing` operand
938
+ */
939
+ spliceInto(parts: LispValue[], value: LispValue): null;
940
+ /**
941
+ * Implementation of the Lisp `unquote` (`,`) special form. Signals an error
942
+ * because unquote is only meaningful inside a `quasiquote` template.
943
+ */
944
+ unquote(): never;
945
+ /**
946
+ * Implementation of the Lisp `unquote-splicing` (`,@`) special form. Signals
947
+ * an error because unquote-splicing is only meaningful inside a `quasiquote`
948
+ * template.
949
+ */
950
+ unquoteSplicing(): never;
951
+ /**
952
+ * Implementation of the Lisp `rplaca` special form; destructively replaces the car of a Cons.
953
+ * @param args the argument Cons containing the target Cons expression and the new car value
954
+ * @return the modified Cons
955
+ */
956
+ rplaca(args: Cons): LispValue;
957
+ /**
958
+ * Implementation of the Lisp `rplacd` special form; destructively replaces the cdr of a Cons.
959
+ * @param args the argument Cons containing the target Cons expression and the new cdr value
960
+ * @return the modified Cons
961
+ */
962
+ rplacd(args: Cons): LispValue;
963
+ /**
964
+ * Implementation of the Lisp `setq` special form; assigns values in the local environment.
965
+ * @param args the argument Cons containing alternating (symbol value) pairs
966
+ * @return the last assigned value
967
+ */
968
+ setq(args: Cons): LispValue;
969
+ /**
970
+ * Implementation of the Lisp `set-allq` special form; assigns values in the binding's owning scope.
971
+ * @param args the argument Cons containing alternating (symbol value) pairs
972
+ * @return the last assigned value
973
+ */
974
+ set_allq(args: Cons): LispValue;
975
+ /**
976
+ * Sets the current call depth used for trace and spy indentation.
977
+ * @param aNumber the new depth
978
+ */
979
+ setDepth(aNumber: number): null;
980
+ /**
981
+ * Builds and returns the Lisp-name to method-name dispatch map for special forms.
982
+ * @return the dispatch map
983
+ */
984
+ static setup(): Map<InterpretedSymbol, string>;
985
+ /**
986
+ * Dispatches a special-form call to the corresponding method via the build-in dispatch map.
987
+ * @param form the form whose car is the special-form symbol
988
+ * @return the result of the special-form method
989
+ */
990
+ specialForm(form: Cons): LispValue;
991
+ /**
992
+ * Writes a trace/spy line to the given stream (or stdout) with the current indentation.
993
+ * @param aStream the destination stream, or null/string to fall back to stdout
994
+ * @param line the line to write
995
+ */
996
+ spyPrint(aStream: NodeJS.WritableStream | string | null, line: string): null;
997
+ /**
998
+ * Implementation of the Lisp `terpri` special form; writes a newline to stdout.
999
+ * @return the symbol t
1000
+ */
1001
+ terpri(): InterpretedSymbol;
1002
+ /**
1003
+ * Implementation of the Lisp `time` special form; measures evaluation time in milliseconds.
1004
+ * @param aCons the argument Cons whose car is the form to time
1005
+ * @return the elapsed time in milliseconds
1006
+ */
1007
+ time(aCons: Cons): number;
1008
+ /**
1009
+ * Implementation of the Lisp `trace` special form; enables tracing.
1010
+ * @return the symbol t
1011
+ */
1012
+ trace(): InterpretedSymbol;
1013
+ /**
1014
+ * Implementation of the Lisp `unless` special form.
1015
+ * @param aCons the argument Cons containing the test and body
1016
+ * @return the value of the last body form if the test is nil, otherwise nil
1017
+ */
1018
+ unless(aCons: Cons): LispValue;
1019
+ /**
1020
+ * Implementation of the Lisp `when` special form.
1021
+ * @param aCons the argument Cons containing the test and body
1022
+ * @return the value of the last body form if the test is non-nil, otherwise nil
1023
+ */
1024
+ when(aCons: Cons): LispValue;
1025
+ }
1026
+ //#endregion
390
1027
  //#region src/errors/KeiLispError/index.d.ts
391
1028
  /**
392
1029
  * @class
@@ -450,5 +1087,5 @@ declare class ParseError extends KeiLispError {
450
1087
  constructor(message: string);
451
1088
  }
452
1089
  //#endregion
453
- export { Cons, EvalError, ExitError, InterpretedSymbol, KeiLispError, LispInterpreter, type LispValue, ParseError, Repl };
1090
+ export { Cons, EvalError, Evaluator, ExitError, InterpretedSymbol, KeiLispError, type KeiLispPlugin, LispInterpreter, type LispValue, ParseError, type PluginContext, Repl, StreamManager, Table };
454
1091
  //# sourceMappingURL=index.d.cts.map