mondo: this is the way
This commit is contained in:
parent
7716fdb98e
commit
abc7a1e48d
2 changed files with 12 additions and 10 deletions
|
|
@ -207,11 +207,6 @@ export class MondoParser {
|
||||||
while (chunks.length > 1) {
|
while (chunks.length > 1) {
|
||||||
let [left, right, ...rest] = chunks;
|
let [left, right, ...rest] = chunks;
|
||||||
|
|
||||||
if (right.length && right[0].type === 'list') {
|
|
||||||
// x.(y) => not allowed anymore for now..
|
|
||||||
const snip = this.get_code_snippet(right[0]);
|
|
||||||
throw new Error(`${this.errorhead(right[0])} cannot apply list: expected "(${snip})" to be a word`);
|
|
||||||
}
|
|
||||||
if (!left.length) {
|
if (!left.length) {
|
||||||
const arg = { type: 'plain', value: '_' };
|
const arg = { type: 'plain', value: '_' };
|
||||||
return this.get_lambda([arg], [arg, ...children]);
|
return this.get_lambda([arg], [arg, ...children]);
|
||||||
|
|
@ -342,11 +337,13 @@ export class MondoRunner {
|
||||||
// is list
|
// is list
|
||||||
// the first element is expected to be the function name
|
// the first element is expected to be the function name
|
||||||
const first = ast.children[0];
|
const first = ast.children[0];
|
||||||
const name = first.value;
|
let name;
|
||||||
this.assert(
|
if (first?.type !== 'list') {
|
||||||
first?.type === 'plain',
|
name = first.value; // regular function call e.g. (fast 2 (s bd))
|
||||||
`${this.parser.errorhead(first)} expected function name, got ${first.type}${name ? ` "${name}"` : ''}.`,
|
} else {
|
||||||
);
|
// dynamic function name e.g. "(<speed fast> 2 (s bd))"
|
||||||
|
name = this.evaluate(first);
|
||||||
|
}
|
||||||
|
|
||||||
if (name === 'lambda') {
|
if (name === 'lambda') {
|
||||||
const [_, args, body] = ast.children;
|
const [_, args, body] = ast.children;
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ import {
|
||||||
chooseIn,
|
chooseIn,
|
||||||
degradeBy,
|
degradeBy,
|
||||||
silence,
|
silence,
|
||||||
|
isPattern,
|
||||||
} from '@strudel/core';
|
} from '@strudel/core';
|
||||||
import { registerLanguage } from '@strudel/transpiler';
|
import { registerLanguage } from '@strudel/transpiler';
|
||||||
import { MondoRunner } from '../mondo/mondo.mjs';
|
import { MondoRunner } from '../mondo/mondo.mjs';
|
||||||
|
|
@ -42,6 +43,10 @@ lib['or'] = (...children) => chooseIn(...children); // always has structure but
|
||||||
|
|
||||||
let runner = new MondoRunner({
|
let runner = new MondoRunner({
|
||||||
call(name, args, scope) {
|
call(name, args, scope) {
|
||||||
|
if (isPattern(name)) {
|
||||||
|
// patterned function name, e.g. "s bd . <speed fast> 2"
|
||||||
|
return name.fmap((fn) => fn(...args)).innerJoin();
|
||||||
|
}
|
||||||
const fn = lib[name] || strudelScope[name];
|
const fn = lib[name] || strudelScope[name];
|
||||||
if (!fn) {
|
if (!fn) {
|
||||||
throw new Error(`[moundough]: unknown function "${name}"`);
|
throw new Error(`[moundough]: unknown function "${name}"`);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue