Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62088 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 41596 invoked from network); 8 Aug 2012 20:42:28 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 8 Aug 2012 20:42:28 -0000 Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.42 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.215.42 mail-lpp01m010-f42.google.com Received: from [209.85.215.42] ([209.85.215.42:65197] helo=mail-lpp01m010-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id BA/00-41247-33FC2205 for ; Wed, 08 Aug 2012 16:42:28 -0400 Received: by lahl5 with SMTP id l5so376159lah.29 for ; Wed, 08 Aug 2012 13:42:23 -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=DQLb9/xr776Mhc7YOO/9doUkoleZ85fy7Rb8w055po0=; b=MQw3sUBmgJa04UE1zOdewIiKwO9XLJWQMiS1cmnYn2XBkIeo6vlHhUTpel7DnCZ9KE Y3EFXxe/O+7Cg0Y9d0H6uUxaUyIjVHXuos3SpFRRij7mvP8MFpyw1Bj44sHVY2LNuYwe cegiStxRNg++2uixcL511+9LaqtCydopvrl+JCA722bhnAlIYG6x5qx4yz0dl0dzh9XZ v2VVCnge/Ku9N2HGqM9LjNrRiowJGcOXLhfl7jC3OuIlCVJgWs76o49V6W7prygGPXqm +t82JAyLMQhm/CTvGrmyJZwlWanz38rpt2lJ+GgkBZXOLKNoYK/a/owBOqPkPaxMVzPb kDcw== MIME-Version: 1.0 Received: by 10.112.42.34 with SMTP id k2mr6716250lbl.11.1344458543563; Wed, 08 Aug 2012 13:42:23 -0700 (PDT) Received: by 10.152.114.70 with HTTP; Wed, 8 Aug 2012 13:42:23 -0700 (PDT) In-Reply-To: <5022CBAE.4010609@ajf.me> References: <50108D60.9090509@sugarcrm.com> <5022CBAE.4010609@ajf.me> Date: Wed, 8 Aug 2012 22:42:23 +0200 Message-ID: To: Andrew Faulds Cc: Stas Malyshev , Nikita Popov , 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:27 PM, Andrew Faulds wrote: > Hi Nikita, > > I notice you require brackets round yield $k => $v and yield $v. Is this the > formal syntax, i.e. '(' T_YIELD var => var ')'? If so it makes sense in a > way, but it feels a little hackish. Does yield $v cause some sort of parsing > issue that putting it in brackets solves? I realise that it's less > ambiguous, but I don't like the idea of it. PHP's syntax has enough special > cases already IMO. Without parenthesis their behavior in array definitions and nested yields is ambigous: array(yield $key => $value) // can be either array((yield $key) => $value) // or array((yield $key => $value)) yield yield $key => $value; // can be either yield (yield $key) => $value; // or yield (yield $key => $value); Apart from that particular case there is the general operator precedence inclarity, e.g. yield $foo . $bar; // could be (yield $foo) . $bar; // or yield ($foo . $bar); This obviously is not a problem per-se, but with yield-style unary operators the precedence rules are often hard to figure out. E.g. most people would probably think that if (include('foo.php') == true) { ... } would be check the return value of include, but it's actually not. Rather it includes the file ('foo.php') == true, which is ''. Another issue was a purely implementational: In order to support by-ref yielding I have to distinguish between variable and non-variable expressions, which breaks the usual precedence rules. I was not able to fix the shift/reduce conflicts that are created by this without requiring the parenthesis. Also I'd like to mention that Python also has the paren-requirement for yield-expressions. It even requires parens for a simple yield, i.e. you'd have to write "data = (yield)". This is not necessary in PHP, because PHP has semicolons. Nikita