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

Function declareSequence

src/compute-engine/engine-sequences.ts:30–66  ·  view source on GitHub ↗
(
  ce: IComputeEngine,
  name: string,
  def: SequenceDefinition
)

Source from the content-addressed store, hash-verified

28} from './oeis.js';
29
30export function declareSequence(
31 ce: IComputeEngine,
32 name: string,
33 def: SequenceDefinition
34): IComputeEngine {
35 // Validate basic requirements (without parsing)
36 if (!def.base || Object.keys(def.base).length === 0) {
37 throw new Error(`Sequence "${name}" requires at least one base case`);
38 }
39 if (!def.recurrence) {
40 throw new Error(`Sequence "${name}" requires a recurrence relation`);
41 }
42
43 // Declare the symbol first with a placeholder handler
44 // This ensures the symbol exists when we parse the recurrence
45 ce.declare(name, {
46 subscriptEvaluate: () => undefined,
47 });
48
49 // Now validate and create the actual handler
50 const validation = validateSequenceDefinition(ce, name, def);
51 if (!validation.valid) {
52 throw new Error(validation.error);
53 }
54
55 // Create the full subscriptEvaluate handler
56 const handler = createSequenceHandler(ce, name, def);
57
58 // Update the symbol's subscriptEvaluate handler
59 // We need to access the internal definition to update it
60 const boxedDef = ce.lookupDefinition(name);
61 if (boxedDef && isValueDef(boxedDef)) {
62 boxedDef.value.subscriptEvaluate = handler;
63 }
64
65 return ce;
66}
67
68export function getSequenceStatus(
69 ce: IComputeEngine,

Callers

nothing calls this directly

Calls 6

createSequenceHandlerFunction · 0.90
isValueDefFunction · 0.90
keysMethod · 0.65
declareMethod · 0.65
lookupDefinitionMethod · 0.65

Tested by

no test coverage detected