Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62108 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34125 invoked from network); 9 Aug 2012 17:39:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 17:39:20 -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.217.170 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:53209] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/2C-00812-7C5F3205 for ; Thu, 09 Aug 2012 13:39:20 -0400 Received: by lbbgp3 with SMTP id gp3so449190lbb.29 for ; Thu, 09 Aug 2012 10:39:16 -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; bh=DzFmSrxlocMzAbAnaD//QTIWuWO+2tFvPixXkP9pcJQ=; b=ku+8/zUFLTptTmnct24Mv8j7KXZNrfgduZMoqw9y2YHkbb0BhkebpW20Ocqfyay7Fe cOUacBlc6B6S1dmaSPq5mz2kpSl/AF7v1SpEmLSeHh6Jf+zQ4iz0O4v2xUZ6rk1xWc9m fK7/vObjwZgnaCm0XgxYOgO/JiEYsVfE1SEYw8xKon/m8ESIrDdQU9fE+1xoCcBNGgTS hPjmDQIJ9ThS/YYk1f+jIM/ixJYoDpLypegl0psAKxsImCSZom+yVvcrd7XSS/p6CczY H5EHZf7xuEHfxXsKUwMGXmGga/uDLIdtB9E/CtKh5pDvOVgWXDwd/ZLjBfxuL95Kwhqb udSQ== MIME-Version: 1.0 Received: by 10.112.42.34 with SMTP id k2mr1179943lbl.11.1344533956290; Thu, 09 Aug 2012 10:39:16 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Thu, 9 Aug 2012 10:39:16 -0700 (PDT) In-Reply-To: <5023DE5E.9000308@ajf.me> References: <50108D60.9090509@sugarcrm.com> <5022CF62.7060705@sugarcrm.com> <5022D22B.9050906@ajf.me> <5023DE5E.9000308@ajf.me> Date: Thu, 9 Aug 2012 19:39:16 +0200 Message-ID: To: Andrew Faulds Cc: Stas Malyshev , PHP internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] Generators in PHP From: nikita.ppv@gmail.com (Nikita Popov) On Thu, Aug 9, 2012 at 5:59 PM, Andrew Faulds wrote: > 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. I definitely can see that yield() is a plausible syntax, but I still think that the normal yield notation is better suited. Another reason is the following: PHP has several constructs with a yield-like syntax. Examples are "include $file" (and require etc) and "print $string". Both are keyword expressions, so they are rather similar to yield. On the other hand there are also other constructs which use the function notation. Like isset(), empty(), etc. The main distinction between them is their primary use: Both include and print are usually used as statements, not as expressions. Writing $foo = include "bar"; is something you rarely do. So here the friendlier keyword notation is chosen. isset() and empty() on the other hand are pretty much always used as expressions (they really don't make sense as statements). So the function-like syntax is chosen here, because it causes less ambiguities. For yield the same applies. Yield will be primarily used as a statement. The vast majority of cases will just be yield $someValue; The expression use is just secondary here. And even there the value-less yield (the one that does not need parens) is the most common case: $data = yield; The case where you want to both receive and send at the same time is rather rare (mostly for trampoline patterns or task scheduling). So I think we should not sacrifice the most common cases for slightly better syntax in the rare cases. Also, currently yield looks very similar to return and I think this is a nice thing as it is similar semantically. yield($foo) would give it different semantics, imho. Nikita