Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62105 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26875 invoked from network); 9 Aug 2012 15:58:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 9 Aug 2012 15:58:08 -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:41548] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/CA-00812-F0ED3205 for ; Thu, 09 Aug 2012 11:58:08 -0400 Received: by lbbgp3 with SMTP id gp3so385835lbb.29 for ; Thu, 09 Aug 2012 08:58:04 -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=5wwHRzjMINlZ/cVoeVP133aN3nNaYz9Ykgf0ymVP6b8=; b=s8co9mE+qhsJJUwDYHH7zAsixYydyDrHZR0h3VQcE1ktZa0qiFPZ3jrd4FGcNsru7i T8g9OhiUtgRMbRMBcSRqizZUqme/4ZOlOaJzLvR5alrj/Cck+qw+3l0J8nqPz7mGcp7K Rjt4OnUt00aN+m0assv7AhNVQK4lToZa1iIDi9EqWokyVCpu2Xn7k8AZUZb4Dl2fBROp zWatNsBcBHwiufqgaqA9yPeDDUYMkA5CM0EwL3DPFbFjn9hb1/JgM+Ob1Ry5IH2aojiP H5gWOk4B4VCuXZLIOHr0O1nMehA+ZjglDq9sI4MDfC/0aeohcEDHNLoHv+nG/dI4/8n0 Jzxg== MIME-Version: 1.0 Received: by 10.152.125.116 with SMTP id mp20mr4558831lab.19.1344527884720; Thu, 09 Aug 2012 08:58:04 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Thu, 9 Aug 2012 08:58:04 -0700 (PDT) In-Reply-To: <5022D22B.9050906@ajf.me> References: <50108D60.9090509@sugarcrm.com> <5022CF62.7060705@sugarcrm.com> <5022D22B.9050906@ajf.me> Date: Thu, 9 Aug 2012 17:58:04 +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 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. 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. Nikita