Re: [RFC] Generators
| From: | Nikita Popov | Date: | Sat, 18 Aug 2012 13:19:41 +0000 |
| Subject: | Re: [RFC] Generators | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-62238@lists.php.net to get a copy of this message | ||
On Sat, Aug 18, 2012 at 2:21 PM, Derick Rethans <derick@php.net> wrote:
> I've some comments how that I've read the RFC:
>
>> Recognition of generator functions
>>
>> 1. Any function which contains a yield statement is automatically a
>> generator function.
>>
>> 2. The initial implementation required that generator functions are
>> marked with an asterix modifier (function*). This method has the
>> advantage that generators are more explicit and also allows for
>> yield-less coroutines.
>>
>> The automatic detection was chosen over the asterix modifier for the
>> following reasons:
>
> I am against this. This is even more magic in PHP. Is it really that
> difficult to have to mark the function with a different keyword, such as
> "generator":
There was already a rather long discussion on this topic. Most of it
is noise, but I filtered out a few mails from Sara and Rasmus as they
probably are of most interest:
http://markmail.org/message/xzhdhbjozb4yrhh3
http://markmail.org/message/ryhygtimpd7q2nok
http://markmail.org/message/32fklwqykpk56iph
http://markmail.org/message/w2kbh7psplnmctcr
>> yield: Yields the value null with an auto-incrementing integer key.
>
> What is the usecase for this?
Use case is
$data = yield;. In that case you don't care about what
you yield (so just the default value and key are yielded), you are
only interested in what you get sent back.
Nikita