Skip to content

Calling some user functions directly in bundle code will cause unexpected error #689

@leeyi45

Description

@leeyi45

Here are some fairly contrived examples of code that will fail at runtime:

with rune (the rune animation errors):

import { animate_rune, heart, stack_frac } from 'rune';

function f(i) {
    return i >= 10 ? heart : stack_frac(1/i, f(i + 1), heart);
}

animate_rune(1, 60, f);

with repl (evaluating any code inside the repl will cause an error):

import { set_evaluator } from 'repl';

function string_length(str) {
    function f(i) {
        return char_at(str, i) === undefined ? i : f(i + 1);
    }
    
    return f(0);
}

function evaller(code) {
    if (string_length(code) === 10) {
        return 0;
    }
    return evaller(code + '');
}

set_evaluator(evaller);

What's happening is that the transpiler does some magic to make tracking recursive calls in user defined functions easier, but it means that functions need to be called using callIfFuncAndRightArgs.

Either that or js-slang's implementation of handling user defined functions needs to change

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions