Re:Coconut – Pythonic functional programming language
by fovc on Thursday June 23, 2016 @09:18PM
(#11965566)
Since Python 3, both generators and lists create a new stack frame. [1] (2nd to last paragraph)
[1] http://python-history.blogspot.com/2010/06/from-list-compreh...
Re:Coconut – Pythonic functional programming language
by warbiscuit on Friday June 24, 2016 @11:12AM
(#11970366)
I'm not meaning when the comprehension is invoked, but during each iteration of the loop within the comprehension.
When doing something like `map(lambda x: 2+x, range(100))`, there will be 101 frames created: the outer frame, and 100 for each invocation of the lambda.
Whereas `[2+x for x in range(100)]` will only create 2: one for the outer frame, and one for the comprehension.
In theory I suppose the VM could have a map() implementation which opportunistically extracts the code from a lambda and inlines them when possible; but doubt CPython does that. OTOH, I'd be surprised if PyPy doesn't do something like that.