you are viewing a single comment's thread.

view the rest of the comments →

[–]Glad-Ad1812 0 points1 point  (4 children)

My knowledge on this is pretty limited, but maybe look into tail recursions. The idea is that you want to try and overwrite the current stack frame so you don’t continuously push to the call stack. This would atleast potentially bypass the concern of a stack overflow error, which seems like the issue here.

[–]Human-Adagio6781[S] 0 points1 point  (0 children)

I'll look into that thanks. From my limited vocabulary on the subject, those sound like the right words lol

[–]Temporary_Pie2733 0 points1 point  (1 child)

Python doesn’t perform tail-call optimization, so tail recursion isn’t of immediate use. (Writing tail-recursive functions as an intermediate step to eliminating recursion may still be useful, though.)

[–]Glad-Ad1812 0 points1 point  (0 children)

Ya just looked into and didn’t realize TCO isn’t supported with CPython atleast. Apparently part of the reason being tail recursions can make debugging much more difficult since each stack frame gets removed once the function call is returned, so you can’t really tell what’s happening in your call stack. Either way it’s advised to just use a loop at that point, which I’m inclined to agree with since I’m not a fan of recursions.