On Thu, 11 Mar 2004 12:01:57 -0500, Peter Hansen <peter at engcorp.com>
>David MacQuigg wrote:>>> 'yield' is a little closer to the intent, but again, to most new users>> it probably means something more like 'give way' or 'acquiesce', the>> opposite of 'resist'. If you had never seen 'yield' used as it is now>> in Python, and your first encounter with generator functions was when>> you saw @return, would you not think "Ah yes, a modified return.", and>> would that not be closer to reality than whatever you might associate>> with the word 'yield'?>>No! The "give way" meaning is _much_ closer to what is going on than >"modified return", in my way of looking at it. Return winds up the call >stack and just happens to include a result value. Yield temporarily >"gives way" but leaves the stack frame in place, available for >resumption at a later time. You could say that the result value is >incidental, in the return case, while the permanent transfer of context >is the key thing. Just the opposite in the case of yield, and therefore >much different from a "modified return".
A normal return terminates the function and returns a result. A
modified return (yield) suspends the function and returns a result.
>This is all semantics, probably, but I don't believe you can make a >strong case that yield is an ill-chosen name.
It's not ill chosen, just arbitrary. I would be just as happy with
'rtn' or 'tsr' or any fanciful word that doesn't convey a _wrong_
We seem to have lost the top of this sub-thread, which is what I was
>- Python is a readable language. lambda says "function literal",> yield says "generator",
All I'm saying is that these names don't convey the stated meanings to
most new users. I could be wrong, as I haven't done a survey.