Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84230 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 98771 invoked from network); 3 Mar 2015 12:09:06 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Mar 2015 12:09:06 -0000 Authentication-Results: pb1.pair.com header.from=bobwei9@hotmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=bobwei9@hotmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain hotmail.com designates 65.55.111.101 as permitted sender) X-PHP-List-Original-Sender: bobwei9@hotmail.com X-Host-Fingerprint: 65.55.111.101 blu004-omc2s26.hotmail.com Received: from [65.55.111.101] ([65.55.111.101:51848] helo=BLU004-OMC2S26.hotmail.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 3D/E4-03783-164A5F45 for ; Tue, 03 Mar 2015 07:09:06 -0500 Received: from BLU436-SMTP139 ([65.55.111.71]) by BLU004-OMC2S26.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.22751); Tue, 3 Mar 2015 04:09:03 -0800 X-TMN: [qHCkreA2yStO9agVKfCdpcWb0IwTMdP8] X-Originating-Email: [bobwei9@hotmail.com] Message-ID: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 (Mac OS X Mail 8.2 \(2070.6\)) In-Reply-To: <54F59C45.7080704@gmail.com> Date: Tue, 3 Mar 2015 13:08:58 +0100 CC: Niklas Keller , Daniel Lowrey , "internals@lists.php.net" Content-Transfer-Encoding: quoted-printable References: <54F59C45.7080704@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.2070.6) X-OriginalArrivalTime: 03 Mar 2015 12:09:01.0052 (UTC) FILETIME=[D59F1BC0:01D055AA] Subject: Re: [PHP-DEV] [RFC Discuss] Generator Delegation From: bobwei9@hotmail.com (Bob Weinand) > Am 03.03.2015 um 12:34 schrieb Rowan Collins = : >=20 > Niklas Keller wrote on 03/03/2015 10:55: >>=20 >> Gr, top-posting... >>=20 >>=20 >> Sorry, was on mobile. ;-) >>=20 >> However, since the existence of the word "yield" is the only thing >> that >> marks a coroutine now, how about using a variant of that for the = final >> value, e.g. "yield final $foo"? >>=20 >>=20 >> What's the final value? The last "yield"ed value or a return? >=20 > "yield final" would mark the final result of the coroutine, as opposed = to the intermediate values passed out with a normal "yield". >=20 >=20 >> Just to give you some real world example: >> If you're using "return", it would look like that: >>=20 >> public function getSession ($sessionId) { >> $result =3D yield $this->redis->get("session.{$sessionId}")); // = We're waiting here until redis responded. >> return json_decode($result); >> } >=20 > My suggestion is simply to change the keyword: >=20 > public function getSession ($sessionId) { > $result =3D yield $this->redis->get("session.{$sessionId}")); // = We're waiting here until redis responded. > yield final json_decode($result); > } >=20 >=20 > The reasoning being that when you run getSession(42), it *doesn't* = return the result of json_decode(), it returns a pointer to the = coroutine's state, which you can resume later. >=20 > Actually, I don't think that example makes sense, because JSON gets = sent out at the first yield, and then sent back in, so the caller would = look something like this: >=20 > $foo =3D getSession(42); > $json_data =3D $foo->current(); > $foo->send($json_data); > $decoded =3D $foo->getReturn(); >=20 > But never mind, I think we both get the idea. >=20 > I understand the desire for a "final result", but I don't like reusing = the word "return", because it's never "returned" as the result of = running the function, it's just made available through some specific = method/syntax. >=20 > Regards, > --=20 > Rowan Collins > [IMSoP] Hey, We currently already have "return;" (without value) as allowed syntax to = terminate Generator execution. Thus, the logical consequence is just = adding a value to that return. Also=E2=80=A6 if you "yield final" a value=E2=80=A6 then it logically = would go into the generator resolving function as it's just like a = normal yield (it's a last one, but still a yield). Would be weird to = yield a value as explicit return value. When we want to *return*, it should be also a real *return". Yes, it is = just accessible through special syntax (or a method), but it's still = *return*ing into the calling frame. Why should the word "return" be unique to methods or functions? Bob=