import { CaretNode, h, t, VNode } from "@caret-js/core"; import { VariableNode } from "./variable"; export class FunctionDefinitionNode extends CaretNode { constructor( public name: string, public args: VariableNode[] = [], public body: CaretNode ) { super(); } static from( name: string, args: VariableNode[] = [], body: CaretNode ): FunctionDefinitionNode { return new FunctionDefinitionNode(name, args, body); } toDebugMathML(): VNode { return h( "mrow", {}, h("mi", {}, t(this.name)), h("mo", { stretchy: "true" }, t("(")), ...this.args.flatMap((arg, index) => [ arg.toDebugMathML(), index < this.args.length - 1 ? h("mo", {}, t(",")) : null, ]), h("mo", { stretchy: "true" }, t(")")), h("mo", {}, t("=")), this.body.toDebugMathML() ); } }