You're using recursion. `runreq()` calls `sum_()` which calls `sum()` in `return l[0] + f(f, l[1:])`, where `f` is `sum()`
No, see GP.
> `runreq()` calls `sum_()` which calls `sum()` in `return l[0] + f(f, l[1:])`, where `f` is `sum()`
Also no, see GP.
def sum_(f, l): if not l: return 0 return l[0] + f(f, l[1:]) def runreq(f, *args): return f(f, *args) print(995,runreq(sum_, range(1,995))) print(1000,runreq(sum_, range(1,1000)))
995 494515 Traceback (most recent call last): File "/tmp/sum.py", line 9, in <module> print(1000,runreq(sum_, range(1,1000))) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/tmp/sum.py", line 6, in runreq return f(f, *args) ^^^^^^^^^^^ File "/tmp/sum.py", line 3, in sum_ return l[0] + f(f, l[1:]) ^^^^^^^^^^^ File "/tmp/sum.py", line 3, in sum_ return l[0] + f(f, l[1:]) ^^^^^^^^^^^ File "/tmp/sum.py", line 3, in sum_ return l[0] + f(f, l[1:]) ^^^^^^^^^^^ [Previous line repeated 995 more times] RecursionError: maximum recursion depth exceeded in comparison
You're using recursion. `runreq()` calls `sum_()` which calls `sum()` in `return l[0] + f(f, l[1:])`, where `f` is `sum()`