lips icon indicating copy to clipboard operation
lips copied to clipboard

Use trampoline on all recursive functions inside JavaScript

Open jcubic opened this issue 5 years ago • 1 comments

This code throw error with stack overflow

(range 10000)

There are two reasons first Pair.fromArray is recursive second cycle detection is also recursive.

To solve the problem all recursive function in JavaScript should use trampoline so it don't overflow the stack.

jcubic avatar Sep 10 '20 09:09 jcubic

range is fixed the same as cylce detection, for this one case one thing that remain is Pair.toString that's recursive. For toString I can use code from my StackOverflow question Trampoline based linked list (lisp tree) to string with cycles, the code is using monads in JavaScript but I think that I can use it.

jcubic avatar Nov 23 '20 13:11 jcubic