Extending Python Syntax with @

Peter Hansen peter at engcorp.com
Thu Mar 11 12:01:57 EST 2004


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".

This is all semantics, probably, but I don't believe you can make a 
strong case that yield is an ill-chosen name.

-Peter



More information about the Python-list mailing list