P.J. Eby wrote:
Now, if somebody came up with a different way to spell the extra value return, I wouldn't object as much to that part. I can just see people inadvertently writing 'return x' as a shortcut for 'yield x; return',
Well, they need to be educated not to do that. I'm not sure they'll need much education about this anyway. They've already been taught not to say 'return' when they mean 'yield', so I don't see why they should suddenly start doing so now. I'd be disappointed to lose that part of the proposal. Part of my philosophy is that suspendable functions should have the same rights and privileges as ordinary ones, and that includes the ability to return values using 'return'.
It also seems weird that the only syntactically-supported way to get the generator's "return value" is to access it inside *another* generator... which *also* can't return the return value to anyone!
Would you be happier if some syntactic way to do that were provided? It could perhaps be done by enhancing the part of the 'for' loop that gets executed upon normal termination of the iterator. for x in my_iter: do_something_with(x) else v: handle_return_value(v)
The unusual spelling would also signal that something unusual (i.e., multitasking) is taking place, similar to the way some frameworks use things like 'yield Return(value)' to signal the end of a task and its return value, in place of a value in the stream.
Difference in philosophy again. To me, the need for such an unusual construct when using these frameworks is a wart, not a feature. -- Greg _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com