Re: [RFC Discuss] Generator Delegation
| From: | Bob Weinand | Date: | Mon, 02 Mar 2015 10:41:43 +0000 |
| Subject: | Re: [RFC Discuss] Generator Delegation | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-84163@lists.php.net to get a copy of this message | ||
> Am 02.03.2015 um 11:28 schrieb Niklas Keller <me@kelunik.com>:
> 2015-03-02 11:11 GMT+01:00 Bob Weinand <bobwei9@hotmail.com
> <mailto:bobwei9@hotmail.com>>:
> > Am 02.03.2015 um 01:17 schrieb Niklas Keller <me@kelunik.com
> > <mailto:me@kelunik.com>>:
> >
> > 2015-03-02 0:52 GMT+01:00 Daniel Lowrey <rdlowrey@php.net
> > <mailto:rdlowrey@php.net>>:
> >
> >> 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
> >> <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
> >> <https://wiki.php.net/rfc/generator-return-expressions>
> >>
> >>
> >> Thanks for your time,
> >>
> >> Daniel
> >>
> >
> > The proposed syntax has an issue:
> >
> > <?php
> >
> > function a () {
> > echo yield * 3;
> > }
> >
> > $a = a();
> > $a->send(42);
> >
> > http://3v4l.org/n1sGb#v550
> > <http://3v4l.org/n1sGb#v550>
> >
> > This is currently valid PHP.
> >
> > Regards, Niklas
>
> Hey,
>
> I think we could use "yield from" as operator here.
>
> Yes, BC. So, I won't make "from" a keyword, but rather specify an own token for
> "yield from" (T_YIELD_FROM).
> That way we have no BC break, except someone tries to yield a constant named "from".
> I think that's a really minor break … and in case this breaks someones code, he needs to wrap
> the constant in parenthesis: "yield (from)".
>
> We can have nice syntax here with a minimal break, so, then, why not?
>
> Thanks,
> Bob
>
> If those keywords can be combined to one, that would be totally fine.
> I think BC breaks are less a problem when the lexer RFC passes, but that shouldn't lead to
> a lot more keyboards being added.
> So yield from will be totally fine, it's already used in other languages.
>
> Regards, Niklas
As said, I won't add a "from" keyword. It's just the combination of
"yield" and "from" with will be interpreted differently at lexer level.
And yes, that's how e.g. Python calls it too, hence this suggestion.
Bob