MCPcopy Create free account
hub / github.com/cortex-js/compute-engine / wrapRecursion

Function wrapRecursion

src/compute-engine/function-utils.ts:435–447  ·  view source on GitHub ↗

Wrap a lambda so each invocation is counted against `recursionLimit`: a * runaway user-function recursion (`f(x) := … f(x-1) …` with no reachable base * case) throws a `CancellationError` (`cause: 'recursion-depth-exceeded'`) * instead of overflowing the native JS call stack with a `RangeError`.

(
  ce: ComputeEngine,
  fn: (params: ReadonlyArray<Expression>) => Expression | undefined
)

Source from the content-addressed store, hash-verified

433export function canonicalFunctionLiteralOperands(
434 ce: ComputeEngine,
435 ops: ReadonlyArray<Expression>
436): Expression | undefined {
437 if (ops.length === 1) {
438 const [body, params] = anonymousParameters(ops[0]);
439 if (params.length > 0)
440 return canonicalFunctionLiteralArguments(ce, [body, ...params]);
441 }
442 return canonicalFunctionLiteralArguments(ce, ops);
443}
444
445/**
446 * The anonymous ("wildcard") parameters `_`, `_1`, … `_9` that `expr` uses, in
447 * index order, together with the body in which the bare `_` has been
448 * normalized to `_1`. The parameter list is empty when the expression uses no
449 * wildcard — the caller then decides what the parameters are (the shorthand
450 * path falls back to the body's unknowns; the `["Function", body]` path keeps

Callers 1

makeLambdaFunction · 0.85

Calls 3

fnFunction · 0.85
_enterRecursionMethod · 0.65
_exitRecursionMethod · 0.65

Tested by

no test coverage detected