On Mon, Aug 20, 2012 at 1:56 PM, Ángel González <keis...@gmail.com> wrote: > On 20/08/12 02:01, Rasmus Lerdorf wrote: >> I would still like to understand what this generator keyword would >> actually do. I don't see how it would work. Would a function marked >> generator somehow not be allowed to return normally or to finish and not >> return anything? How could this be enforced? I am completely against any >> keyword that is essentially documentation-only. >> >> -Rasmus > Given that such function could "return several times", seems a different > enough function type to have its keyword. The method signature defines the API, so the caller knows what to use. Can we agree on that? In this case it makes absolutely no difference to the caller whether the function is implemented using a generator, or whether it returns a custom Iterator object. The "generator" keyword wouldn't document the API, it would document an implementation-detail.
What would *actually* make sense here are return value typehints. E.g. one could have something like `public Iterator getIterator() { ... }`. This would provide the caller with information on what the function returns, but would leave out the implementation detail that the Iterator was implemented using a generator. Or, if the generator implementation is actually important (because it is used as a coroutine) one could also explicitly typehint against it: `public Generator getCoroutine() { ... }`. But return-value type hints are not directly related to generators. They are a more general concept. If that's what all of you want, then I'd recommend opening up a new thread for it. > You could not decorate it and rely instead on the presence of the yield > keyword, but parsers will thank knowing about it from the start rather > than realising at mid-parsing that the function is a completely > different beast. No, parsers don't care about this. It's trivial to detect in both cases. Nikita -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php