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

Function skeletonize

src/compute-engine/rubi/compile.ts:61–70  ·  view source on GitHub ↗

Replace Blank/BlankOptional atoms with placeholder symbols.

(expr: Json, variable: string)

Source from the content-addressed store, hash-verified

59const VAR = 'RUBIPATVARX';
60
61function isCall(x: Json, op: string): x is Json[] {
62 return Array.isArray(x) && x[0] === op;
63}
64
65/** Replace Blank/BlankOptional atoms with placeholder symbols. */
66function skeletonize(expr: Json, variable: string): Json {
67 if (isCall(expr, 'Blank') || isCall(expr, 'BlankOptional')) {
68 const name = expr[1] as string;
69 if (name === variable) return VAR;
70 return (expr[0] === 'BlankOptional' ? OPT : SLOT) + name;
71 }
72 if (Array.isArray(expr))
73 return expr.map((a, i) => (i === 0 ? a : skeletonize(a, variable))) as Json;

Callers 1

compileRuleFunction · 0.85

Calls 2

isCallFunction · 0.85
mapMethod · 0.65

Tested by

no test coverage detected