mondo: def node

This commit is contained in:
Felix Roos 2025-03-30 11:43:01 +02:00
parent b4027fd92a
commit a0fb8fb37f
No known key found for this signature in database
3 changed files with 27 additions and 11 deletions

View file

@ -49,15 +49,19 @@ function evaluator(node, scope) {
if (type === 'list') {
const { children } = node;
const [name, ...args] = children;
if (name.value === 'def') {
return silence;
}
// name is expected to be a pattern of functions!
const first = name.firstCycle(true)[0];
if (typeof first?.value !== 'function') {
throw new Error(`[mondough] "${first}" is not a function`);
const type = typeof first?.value;
if (type !== 'function') {
throw new Error(`[mondough] "${first}" is not a function, got ${type} ...`);
}
return name
.fmap((fn) => {
if (typeof fn !== 'function') {
throw new Error(`[mondough] "${fn}" is not a function`);
throw new Error(`[mondough] "${fn}" is not a function b`);
}
return fn(...args);
})
@ -80,7 +84,6 @@ function evaluator(node, scope) {
if (node.loc) {
pat = pat.withLoc(node.loc[0], node.loc[1]);
}
pat.foo = true;
return pat;
}