I have this recursive function:
def lifecycle(population):
...
lifecycle(new_population)
I want to perform this loop 100 times. I want to use correct functional style. So, I cannot use a counter? Because assigning new values to a variable is not okay in functional programming. How does one do this functionally? I’m using Python.
Technically, like this:
But this is a really, really silly thing to do in Python (and it fails for all but the smallest examples, due to tail calls being not optimized). Just use a loop, although that uses mutable state under the hood, the remaining program can be perfectly functional.