Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62086 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38079 invoked from network); 8 Aug 2012 20:15:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2012 20:15:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:53445] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6F/92-29512-3C8C2205 for ; Wed, 08 Aug 2012 16:15:00 -0400 Received: by lahl5 with SMTP id l5so359896lah.29 for ; Wed, 08 Aug 2012 13:14:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; bh=KF2f8i6+w3xTSYUqXz1UFnFBXlOQAdIBT2JDsZkHW0I=; b=P9m3NiTImklE0VaE1/IBWmhfbDbi9BTQFYwLUGrdvqc2MP6tUxh4iFRiPgX1y/5VFG 0Tn3y8BbdNdcAhtATIa91UZpUoAWMq6gRs6DcN8Kq7wCDYUHlvs8rOkNaTIxNMGGzKOI s/TDUB2aTPJtxUZIwf5TU1XZZnMuyFtkgfZDq+xoez/iIHvDkriBCx09KiPC2vZqKfBP iwff+nmPx98ZezrzktHAo3tBTEFic2oq4kZ5chS6rZKIF2TCOuzJcIOBFjcfj7x12HUh 0MrcOmj9JGdJSlD2h0CkwYkp3InQjwxstENl8Th+SxXpmwEUmS21ruhcFfEHDh21Fpow iLsg== MIME-Version: 1.0 Received: by 10.112.54.100 with SMTP id i4mr8341471lbp.97.1344456897042; Wed, 08 Aug 2012 13:14:57 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Wed, 8 Aug 2012 13:14:56 -0700 (PDT) In-Reply-To: References: <50108D60.9090509@sugarcrm.com> Date: Wed, 8 Aug 2012 22:14:56 +0200 Message-ID: To: Stas Malyshev Cc: Nikita Popov , PHP internals Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Generators in PHP From: nikita.ppv@gmail.com (Nikita Popov) On Fri, Jul 27, 2012 at 8:09 PM, Nikita Popov wrote: >> 5. Are multiple yields allowed? I.e. the rfc mentions something like >> yield yield $a - what that would mean? I'd allow yield only be applied >> to variable expression (lval) because double yield doesn't make sense to >> me, but maybe I miss something. > > yield yield $a would basically first yield $a and then receive some > value (via send) and yield that value again. Nothing you'd normally do > ;) It was mentioned only as a syntax ambiguity consideration. > > Actually I added some additional parenthesis requirements for yield. > For example you'd have to write the above as `yield (yield $a)` now > (which should be slightly more clear). I haven't yet reflected this > change in the RFC, but I'll add a section on it later. > >> 6. =93Sending values=94 section seems to be missing. Especially useful w= ould >> be to cover what happens with keys there and what is the syntax there - >> is it just "$a =3D yield;"? Or does it mean when yield is used in >> expression it becomes incoming yield? And, last but not least - do we >> need sending into generators at all? > > Yeah, I haven't written that section yet. But it is fairly simple: If > you go $generator->send($foo) then $foo will be the result of the > current `yield` expression. And yes, this also works with keys and > values. All of the following are valid: > > $data =3D yield; > $data =3D (yield $value); > $data =3D (yield $key =3D> $value); > > The first case is the most common though. I.e. you usually use it > either as a generator or a reverse generator, not both. But doing both > is also common for cooperative multitasking etc. > > Regarding the last question: I think the feature is worth adding. It > is a very powerful concept that is hard to implement otherwise. Useful > in particular for things like parsing and multitasking. > >> 6. What happens if you send into a by-ref generator? Is the data sent >> by-ref then? What if it's an expression that can't be send by-ref? > > No, sending is always by-value. By-ref only affects the yielding part. I now added the mentioned sections: https://wiki.php.net/rfc/generators#yield_keyword https://wiki.php.net/rfc/generators#sending_values I also added a list of error conditions: https://wiki.php.net/rfc/generators#error_conditions Sorry for the delay, Nikita