Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62089 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42869 invoked from network); 8 Aug 2012 20:43:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2012 20:43:20 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@sugarcrm.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@sugarcrm.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain sugarcrm.com designates 67.192.241.147 as permitted sender) X-PHP-List-Original-Sender: smalyshev@sugarcrm.com X-Host-Fingerprint: 67.192.241.147 smtp147.dfw.emailsrvr.com Linux 2.6 Received: from [67.192.241.147] ([67.192.241.147:57867] helo=smtp147.dfw.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D5/50-41247-66FC2205 for ; Wed, 08 Aug 2012 16:43:19 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp31.relay.dfw1a.emailsrvr.com (SMTP Server) with ESMTP id BB72750915; Wed, 8 Aug 2012 16:43:15 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp31.relay.dfw1a.emailsrvr.com (Authenticated sender: smalyshev-AT-sugarcrm.com) with ESMTPSA id 5635650719; Wed, 8 Aug 2012 16:43:15 -0400 (EDT) Message-ID: <5022CF62.7060705@sugarcrm.com> Date: Wed, 08 Aug 2012 13:43:14 -0700 Organization: SugarCRM User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Nikita Popov CC: PHP internals References: <50108D60.9090509@sugarcrm.com> In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Generators in PHP From: smalyshev@sugarcrm.com (Stas Malyshev) Hi! > https://wiki.php.net/rfc/generators#yield_keyword > https://wiki.php.net/rfc/generators#sending_values I'm not sure $data = (yield $value) makes a lot of sense. Why we have two variables here? Why it is only operator in the language that requires parentheses around? All these complex parentheses rules seem unnecessarily complicated. I'd rather do it in a more simple way: yield in an expression means incoming yield. I.e.: $data = yield; foo(yield, 1, 2); list($a, $b) = yield; Same with: call(yield $value) - what is the meaning of $value here? Why not just call(yield)? I would also not support array((yield $key => $value)) - it seems to be really unclear how it works. I'd just have yield produce a value which was sent, and that's it, and you could use this value in the same way you'd use any other expression. Only question I have here is what happens if you use yield in the middle of function call expression, for example: call(foo(bar(), $foo, yield, 3), baz()); We are kind of stopping the function in the middle of the function call and going to unrelated code here, and may never return back. Where the required cleanups, etc. should happen? Another question is, if my function is like this: function foo() { var_dump(yield); } And I do: foo()->current() - what happens? Do I get null there? What happens if after that I do send() on the same generator? In general, interaction between incoming and outgoing yields is not very clear, especially what happens when you combine them. Also, small point: yield is repeatably called "statement" in the doc, but in fact it can be both statement and expression with returning yield. -- Stanislav Malyshev, Software Architect SugarCRM: http://www.sugarcrm.com/ (408)454-6900 ext. 227