lips
lips copied to clipboard
Use trampoline on all recursive functions inside JavaScript
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.
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.