3 ms·
BTW It'd be nice if python implemented support for tail call recursive or even better, a growable/segmented stack in order to allow arbitrary pythons functions
by SemanticStrengh 4y ago
BTW It'd be nice if python implemented support for tail call recursive or even better, a growable/segmented stack in order to allow arbitrary pythons functions be stack overflow safe.
e.g. https://gcc.gnu.org/wiki/SplitStacks#:~:text=Split%20Stacks%20in%20GCC&text=The%20goal%20of%20split%20stacks,as%20required%20by%20the%20program https://gcc.gnu.org/wiki/SplitStacks#:~:text=Split%20Stacks%....
- jleahy 4y agoThere was once stackless python that did this (Eve online was built in it), I don’t know if it still exists though.
- bqmjjx0kac 4y agoNeat! https://en.wikipedia.org/wiki/Stackless_Python https://en.wikipedia.org/wiki/Stackless_Python Sadly, it isn't true parallelism, more like green threads. And they didn't manage to kill the GIL.
- masklinn 4y agoIf Python doesn't depend on the C stack anymore (for most of its work), that's basically what you'll have for free. Python's own stackframes are heap-allocated and chained (so each function has its own stack, in essence), so its use of a single unified allocation space for stack is already an implementation detail of the interpreter.
- SemanticStrengh 4y agonice
- FreakLegion 4y agoWith Python it's possible to do tail-call optimization yourself. See this all-time great Stack Overflow answer and the linked repo for details (the actual code is quite short): https://stackoverflow.com/a/18506625 https://stackoverflow.com/a/18506625.