From 4208c79c0951ef963026b1454a0cc76ed7294555 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Fri, 2 May 2025 15:13:04 +0200 Subject: [PATCH] fix: ! and @ operators --- packages/mondough/mondough.mjs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/packages/mondough/mondough.mjs b/packages/mondough/mondough.mjs index e995c0e4..d995c3d8 100644 --- a/packages/mondough/mondough.mjs +++ b/packages/mondough/mondough.mjs @@ -49,6 +49,10 @@ function evaluator(node, scope) { if (type === 'list') { const { children } = node; const [name, ...args] = children; + // some functions wont be reified to make sure they work (e.g. see extend below) + if (typeof name === 'function') { + return name(...args); + } if (name.value === 'def') { return silence; } @@ -56,7 +60,7 @@ function evaluator(node, scope) { const first = name.firstCycle(true)[0]; const type = typeof first?.value; if (type !== 'function') { - throw new Error(`[mondough] "${first}" is not a function, got ${type} ...`); + throw new Error(`[mondough] expected function, got "${first?.value}"`); } return name .fmap((fn) => { @@ -73,10 +77,14 @@ function evaluator(node, scope) { return reify(scope[value]); // -> local scope has no location } const variable = lib[value] ?? strudelScope[value]; + // problem: collisions when we want a string that happens to also be a variable name + // example: "s sine" -> sine is also a variable let pat; if (type === 'plain' && typeof variable !== 'undefined') { - // problem: collisions when we want a string that happens to also be a variable name - // example: "s sine" -> sine is also a variable + // some function names are not patternable, so we skip reification here + if (['!', 'extend', '@', 'expand'].includes(value)) { + return variable; + } pat = reify(variable); } else { pat = reify(value);