Daniel Lowrey wrote on 01/03/2015 23:52:
Hi folks,
I'd like to initiate discussion on a proposal to implement generator
delegation via the following new syntax inside generator functions:
yield * <expr>
The Generator Delegation RFC is available here:
https://wiki.php.net/rfc/generator-delegation
This proposal is conceptually related to (and requires functionality
proposed by) the forerunning Generator Return Expressions RFC here:
https://wiki.php.net/rfc/generator-return-expressions
Thanks for your time,
Daniel
Could you explain a bit more about how the generator return
functionality is necessary for this? It seems to me like it's still just
a "nice to have", and that the main functionality - delegating from one
generator to another - is completely separate. Or is there some common
use case that only makes sense if you combine the two features?
The reason I ask is that "yield from" (or whatever syntax) sounds
useful, but I'm not that keen on allowing "return" in generators,
because I can see it further muddying the water between functions and
generators: when you call the following "function", it doesn't actually
return 1 as it would appear at a glance, because the existence of a
yield statement elsewhere in the body magically makes it return a
Generator object instead:
function foo() {
// potentially many lines of code
yield 1;
// potentially many more lines of code
return 1;
}
I would personally have preferred generators to have used a distinct
keyword rather than just looking like functions, but since that ship has
sailed, making them look even more like functions worries me. Is there
perhaps some other syntax that could be used for this "generator result
value"?
Regards,
--
Rowan Collins
[IMSoP]
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php