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

Function apply

src/compute-engine/function-utils.ts:275–298  ·  view source on GitHub ↗
(
  fn: Expression,
  args: ReadonlyArray<Expression>
)

Source from the content-addressed store, hash-verified

273 // Without this gate the shorthand path below reads it as a lambda
274 // BODY and turns its free symbols into parameters, so
275 // `Map(Comparable.compare, xs)` bound each ELEMENT to `Comparable`
276 // and mapped `Field(element, "compare")` — an absence marker per
277 // element. Same predicate as `apply()`'s symbolic-application gate,
278 // so the two tiers agree — plus its syntactic sibling for a RAW
279 // operand (a lazy operator's held callback), whose type still reads
280 // `unknown` and cannot answer the type-based predicate.
281 //
282 if (denotesFunction(expr) || isQualifiedProtocolMember(expr)) return expr;
283
284 //
285 // 6/ Shorthand function literal,
286 // e.g. `["Add", "_", 1]` or `["Add", "x", 1]`
287 //
288 console.assert(expr.operator !== 'Function');
289
290 const ce = expr.engine;
291 let [body, params] = anonymousParameters(expr);
292
293 if (params.length === 0) {
294 // There are no wildcards
295
296 // The caller knows the intended parameter list (`Integrate` passes its
297 // integration variables): build the literal from the RAW body with those
298 // parameters, so body occurrences bind to them through the normal §6.1
299 // pre-declare mechanism in `canonicalFunctionLiteralArguments`. Inferring
300 // parameters from the body's unknowns and swapping the parameter list
301 // afterwards is NOT equivalent: the inferred parameters are declared in

Callers 3

core.tsFile · 0.90
derivativeFunction · 0.90
applyFunctionLiteralFunction · 0.90

Calls 4

isFunctionFunction · 0.90
makeLambdaFunction · 0.85
_fnMethod · 0.65
functionMethod · 0.65

Tested by

no test coverage detected