[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: python_recusion_depth.png (78 KB, 915x893)
78 KB
78 KB PNG
very pythonic, very demure
>>
>>106971022
Hey OP I optimized your code
def doit(n=0x2000):
return "Finished"

doit()
>>
there's never a reason to use tail recursion instead of a loop in python
>>
>>106971022
recursion is only for functional languages like haskell
>>
>>106972037
also this. recursion is superior, but the reality is it fucks with debugging information which is why so many javascript engines drag their feet on the tail call part of the ES262 spec.
>>
>>106972053
depends
>>
>>106971911
python loops leak the counter variable due to shitty scoping, recusion sidesteps that
>>
a brahmin lion doesn't concern himself with recursion
>>
>>106971022
>NOOOOOOOOO WHY DOES IT NOT ALLOW ME TO BLOW UP THE ST--ACK!!
Recursion is a mental illness.
>>
>can't do recursion
signs of a half-baked language
>>
>>106972339
>>106972412
>meanwhile C
>Depth: 261793
>Segmentation fault
#include <stdio.h>

void recurse(int n) {
printf("Depth: %d\n", n);
recurse(n + 1);
}

int main() {
recurse(1);
}
>>
>>106973386
The common C compilers optimize tail calls though
>>
>>106973579
Except when they don't feel like doing it for whatever fucking reason.
So you shouldn't rely on it.
>>
>>106973613
https://clang.llvm.org/docs/AttributeReference.html#musttail
>>
>>106973579
tail call optimization is turning
void f() { f(); }
into
while (1) {}

the compiled code is not recursion anymore, rather it's now a loop
be less retarded, son
>>
>>106973613
>>106973704
retards
>>106973985



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.