UNPKG

@thi.ng/pointfree

Version:

Pointfree functional composition / Forth style stack execution engine

50 lines 1.83 kB
import type { IObjectOf } from "@thi.ng/api"; import type { StackContext, StackProc } from "./api.js"; /** * Higher order word. Takes two stack programs: truthy and falsey * branches, respectively. When executed, pops TOS and runs only one of * the branches depending if TOS was truthy or not. * * Note: Unlike JS `if() {...} else {...}` constructs, the actual * conditional is NOT part of this word. * * Stack effect: `( bool -- ? )` * * @param _then - * @param _else - */ export declare const defCond: (_then: StackProc, _else?: StackProc) => (ctx: StackContext) => StackContext; /** * Non-HOF version of {@link defCond}, expects `test` result and both branches * on d-stack. Executes `thenq` word/quotation if `test` is truthy, else runs * `elseq`. * * Stack effect: `( test thenq elseq -- ? )` * * @param ctx - */ export declare const condq: (ctx: StackContext) => StackContext; /** * Similar to {@link condq}, but only expects `test` result and truthy branch * d-stack. Executes word/quotation if `test` is truthy, else does nothing. * * Stack effect: `( test whenq -- ? )` * * @param ctx - */ export declare const whenq: (ctx: StackContext) => StackContext; /** * Higher order word. Takes an object of stack programs with keys in the * object being used to check for equality with TOS. If a match is * found, executes corresponding stack program. If a `default` key is * specified and no other cases matched, run `default` program. In all * other cases throws an error. * * Important: The default case has the original TOS re-added to the * d-stack before execution. * * @param cases - */ export declare const defCases: (cases: IObjectOf<StackProc>) => (ctx: StackContext) => StackContext; export declare const casesq: (ctx: StackContext) => StackContext; //# sourceMappingURL=cond.d.ts.map