News for hackers. Stuff that matters.
Re:Racketscript by ughitsaaron on Tuesday November 01, 2022 @07:37AM (#33419831)
TCO is a runtime feature that enables code authors to write functions that call out to other functions in such a way that the stack size is not increased. If you’ve ever crossed the `RangeError: Maximum Call Stack Size Exceeded` error, it’s possible that the executed code could’ve benefitted from TCO. TCO is especially invaluable for writing recursive functions (without it, recursion is almost always a bad idea, IMHO).

TCO is technically in the ECMAScript specification (since 2015) but hasn’t been implemented across browsers or runtimes (with a few exceptions).

Dr. Axel has written a good explainer of TCO in the context of Javascript here https://2ality.com/2015/06/tail-call-optimization.html

Re:Racketscript by zeckalpha on Tuesday November 01, 2022 @08:52AM (#33420473)
This can be worked around using trampolines.
Re:Racketscript by ughitsaaron on Tuesday November 01, 2022 @10:17AM (#33421552)
This is the first time I've heard of "trampolines". How interesting.

Do you use this strategy for implementing recursion? Are there consequences or trade offs?

For others who are curious, see

1) https://stackoverflow.com/questions/25228871/how-to-understa..., and 2) https://raganwald.com/2013/03/28/trampolines-in-javascript.h...

Re:Racketscript by soegaard on Tuesday November 01, 2022 @02:33PM (#33425413)
Check "Using ParentheC to Transform Scheme Programs to C or How to Write Interesting Recursive Programs in a Spartan Host (Program Counter)" for more about trampolines.

It's not the only strategy though.

https://stackoverflow.com/q/6003037/23567

Re:Racketscript by zeckalpha on Wednesday November 02, 2022 @07:22PM (#33444245)
You would do this inside a transpiler, rather than manually.