Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62090 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 44734 invoked from network); 8 Aug 2012 20:55:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2012 20:55:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 64.22.89.133 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 64.22.89.133 oxmail.registrar-servers.com Linux 2.6 Received: from [64.22.89.133] ([64.22.89.133:40526] helo=oxmail.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/B0-41247-942D2205 for ; Wed, 08 Aug 2012 16:55:37 -0400 Received: from [192.168.0.200] (5ad4bfa0.bb.sky.com [90.212.191.160]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by oxmail.registrar-servers.com (Postfix) with ESMTPSA id 42DC7C30003; Wed, 8 Aug 2012 16:55:30 -0400 (EDT) Message-ID: <5022D22B.9050906@ajf.me> Date: Wed, 08 Aug 2012 21:55:07 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Stas Malyshev CC: Nikita Popov , PHP internals References: <50108D60.9090509@sugarcrm.com> <5022CF62.7060705@sugarcrm.com> In-Reply-To: <5022CF62.7060705@sugarcrm.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Generators in PHP From: ajf@ajf.me (Andrew Faulds) On 08/08/12 21:43, Stas Malyshev wrote: > 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. > Hmm. This is just a quick thought: Considering the yield syntax will vary about needing () round it, why not make it a "fake" function (language construct). This way it's consistent: yield(), yield($v), yield($k => $v), $a = yield(), etc. (yield $x) is just messy as an expression. We don't have (isset $x), we have isset($x). -- Andrew Faulds http://ajf.me/