[Greg Ewing] > Lying awake thinking about this sort of thing last night, > I found myself wondering if there should be a way of > explicitly requesting that a name be evaluated at closure > creation time, e.g. > > pipe = source > for p in predicates: > pipe = e for e in pipe if ^p(e) > > where the ^ means that p is evaluated in the enclosing > scope when the closure is created, and bound to a slot > which behaves like a default-argument slot (but is > separate from the default arguments). As explained in the original email, the example is also a disaster if pipe's binding isn't captured at creation-time too. > This would allow the current delayed-evaluation semantics > to be kept as the default, while eliminating any need > for using the default-argument hack when you don't > want delayed evaluation. Well, I have yet to see an example where delayed evaluation is of any use in a generator expression, except for a 100%-contrived example that simply illustrated that the semantics can in fact differ (which I hope isn't something anyone questioned to begin with <wink>). Try writing a real example. If it needs delayed evaluation in a plausible way, great. I'm still batting 0 at trying to find such a thing; I confess I wasn't moved by the it = f(x) for x in whatever def f(x): blah example (there being no apparent need to contort the order of the assignments except, again, to illustrate that semantics have consequences).
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4