Skip to content

Fix Language Errors

Find the message, then work through the fix. Quoted blocks are what resonon prints; most errors name the file, line and column where they happened. Every kind of error is listed in Errors & Warnings.

Undefined function ‘Delay’ at …/src/main.non:3:9

  1. Check the spelling. Names are case-sensitive: Delay, not delay.

  2. Import it. Effects, instruments and signals come from standard-library modules, so name them in a use first:

    use "std/effects" { Delay, Reverb };
    use "std/instruments" { Sampler, Kit };
    use "std/signals" { Sine };

    Every module and what it exports is in the standard library reference.

  3. For a function from your own module, use that module — see Modules.

Type error at …/src/main.non:1:13: expected Number, got String

A value of the wrong type reached a function or operator. The column points at it.

  1. Check what you passed against the signature. Hover the function in VSCode to see it.
  2. A MIDI note is a number or a note name: 60 or C4, not "60".
  3. The rules for each type: Values & Types.

Arity mismatch at …/src/main.non:2:2: ‘AudioTrack.pan’ expects 1 arguments, got 2

Compare the call with the signature the message names. Hover the name in VSCode, or look it up in the standard library reference.

Index out of bounds at …/src/main.non:2:8: index 5 is out of range for length 3

Arrays count from 0, so an array of length 3 has the indices 0, 1 and 2.

  1. Check the length with .length().
  2. To go round an array, take the index modulo its length:
let arr = #[10, 20, 30];
for i in range(6) {
print(arr[i % arr.length()]); // 10, 20, 30, 10, 20, 30
}

Duplicate definition at …/src/main.non:2:1: fn ‘greet’ repeats the fn at 1:1. A name has one definition: rename one of them.

Within the code you run, a name has one definition: one fn, class or dsp block, not also a let or an import, and one method or field of that name in a class. Nothing in that code runs until the repeat is gone. The message names both places.

  1. If the two are different things, rename one of them, and its uses.

  2. If you meant a second version with more parameters, keep one definition and give the extra parameters default values:

    fn greet(name = "world") {
    return "hello " + name;
    }
    print(greet());
    print(greet("band"));
  3. If a use is one of the two, rename the import with as, or import only the names you need:

    use "./a.non" { foo };
    use "./b.non" { foo as b_foo };

    Or import the module under a name of your own, and reach through it:

    use "./b.non" as b;
    b.foo();
  4. If you meant to replace the old definition, run the new one on its own. A later run replaces whatever the name meant, an import included; only a repeat within one run is refused.

Parse error at …/src/main.non:2:5: `fn` is a definition, and a definition is written at the top level of a file. For a local function, bind a closure: let f = fn(x) { … };

fn, class and dsp definitions go at the top level of a file, outside any function, loop or block.

  1. Move the definition out, above the code that uses it.

  2. Or, for a helper that belongs to one place, bind a closure:

    fn outer() {
    let inner = fn(x) { return x * 2; };
    return inner(21);
    }
    print(outer());