Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62106 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 28170 invoked from network); 9 Aug 2012 15:59:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 15:59:54 -0000 Authentication-Results: pb1.pair.com header.from=ajf@ajf.me; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ajf@ajf.me; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ajf.me designates 64.22.89.134 as permitted sender) X-PHP-List-Original-Sender: ajf@ajf.me X-Host-Fingerprint: 64.22.89.134 oxmail.registrar-servers.com Linux 2.6 Received: from [64.22.89.134] ([64.22.89.134:55286] helo=oxmail.registrar-servers.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 97/1B-00812-97ED3205 for ; Thu, 09 Aug 2012 11:59:53 -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 114C83E8003; Thu, 9 Aug 2012 11:59:49 -0400 (EDT) Message-ID: <5023DE5E.9000308@ajf.me> Date: Thu, 09 Aug 2012 16:59:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Nikita Popov CC: Stas Malyshev , PHP internals References: <50108D60.9090509@sugarcrm.com> <5022CF62.7060705@sugarcrm.com> <5022D22B.9050906@ajf.me> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Generators in PHP From: ajf@ajf.me (Andrew Faulds) On 09/08/12 16:58, Nikita Popov wrote: > On Wed, Aug 8, 2012 at 10:55 PM, Andrew Faulds wrote: >> 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). > There are two reasons why I would not choose that syntax: > > 1. This would make "yield" look like a functions, without actually > being a function. PHP has done this in the past quite often and I > think it was a mistake. It is the reason why people try to write > empty(someCall()). It looks like a function, so they expect it to > behave like one. Similarly you also can't do $f = 'empty'; $f($foo), > which again is confusing to people new to the language. yield(), so far as the programmer is concerned, might as well be a function. It isn't, strictly speaking, but like other function calls, it suspends execution of the function until the called function completes. So I don't think this is a problem. > 2. Other languages that implement generators also use the "yield $foo" > syntax (and also have the same parentheses requirements). So this > makes PHP consistent with them. Doesn't mean we can't lead the way and have a nicer syntax :) > Nikita -- Andrew Faulds http://ajf.me/