import { U, Cons, Shareable } from '@stemcmicro/tree'; import { Sym, JsAtom } from '@stemcmicro/atoms'; type Sign = -1 | 0 | 1; declare const SIGN_LT = -1; declare const SIGN_EQ = 0; declare const SIGN_GT = 1; type CompareFn = (lhs: U, rhs: U) => Sign; interface ExprHandler { binL(lhs: T, opr: Sym, rhs: U, env: ExprContext): U; binR(rhs: T, opr: Sym, lhs: U, env: ExprContext): U; dispatch(expr: T, opr: Sym, argList: Cons, env: ExprContext): U; /** * TODO: Migrate to using dispatch. */ subst(expr: T, oldExpr: U, newExpr: U, env: Pick): U; /** * TODO: Migrate to using dispatch. */ test(expr: T, opr: Sym, env: ExprContext): boolean; } interface ExprContext extends Shareable { clearBindings(): void; compareFn(opr: Sym): CompareFn; handlerFor(expr: T): ExprHandler; hasBinding(opr: Sym, target: Cons): boolean; getBinding(opr: Sym, target: Cons): U; setBinding(opr: Sym, binding: U): void; hasUserFunction(name: Sym): boolean; getUserFunction(name: Sym): U; setUserFunction(name: Sym, usrfunc: U): void; defineUserSymbol(name: Sym): void; valueOf(expr: U): U; getDirective(directive: number): number; pushDirective(directive: number, value: number): void; popDirective(): void; getSymbolPrintName(sym: Sym): string; hasState(key: string): boolean; getState(key: string): Shareable; setState(key: string, value: Shareable): void; } /** * Here the first argument is the argument list and does not include the operator. */ type LambdaExpr = (argList: Cons, $: ExprContext) => U; declare class Lambda extends JsAtom { #private; readonly type = "lambda"; constructor(body: LambdaExpr, hash: string, pos?: number, end?: number); get hash(): string; get body(): LambdaExpr; equals(other: U): boolean; toString(): string; } declare function is_lambda(expr: U): expr is Lambda; export { type CompareFn, type ExprContext, type ExprHandler, Lambda, type LambdaExpr, SIGN_EQ, SIGN_GT, SIGN_LT, type Sign, is_lambda };