Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unlimit recursive depth #237

Closed
frokaikan opened this issue Jul 8, 2018 · 4 comments
Closed

unlimit recursive depth #237

frokaikan opened this issue Jul 8, 2018 · 4 comments

Comments

@frokaikan
Copy link

frokaikan commented Jul 8, 2018

This will cause an endless loop:

class foo {
func f1() {return 10;}
}
func main() {
var obj = foo();
var n1 = obj.f1();

    func test() {return 1000;}
    obj.bind("f2", main);
    var n2 = obj.f2();                              

    obj.bind("f3", {return 10000;});
    var n3 = obj.f3();                              

    obj.unbind("f2");
    obj.bind("f2", {return 50000;});
    var n4 = obj.f2();                              

    return n1+n2+n3+n4;

}

I think there should be a recursive depth limit (such as 1024?)

@marcobambini
Copy link
Owner

@frokaikan Have you edited this post? Because I received another sample code:

func f(a) {
    System.print(a);
    return f(a-1);
}

func main() {
    return f(0);
}

This is an unlimited loop because the user decided that it should be an unlimited loop.
There is no unique way I can limit the number of recursive calls because this is not probably what an user expects. For example:

func fibonacci (n) {
    if (n<2) return n;
    return fibonacci(n-2) + fibonacci(n-1);
}

func main() {
    return fibonacci(30);
}

In this case the fibonacci function is recursively called more than 2.6 million times. How can I arbitrary set a 2014 limit?

@frokaikan
Copy link
Author

Eh, that is not me... I just want to know if I can set or modify the recursive depth limit.
Maybe there is someone want to know just the same things...

@marcobambini
Copy link
Owner

Fixed by 244c758

You can now control max depth recursion with System.maxRecursionDepth:

func f(a) {
    return f(a-1);
}

func main() {
    System.maxRecursionDepth = 1024;
    return f(0);
}

// RUNTIME ERROR: Max recursion depth exceeded for func f (limit is set to 1024)

@frokaikan
Copy link
Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants