From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10960 invoked by alias); 24 Sep 2014 22:02:18 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 33237 Received: (qmail 7684 invoked from network); 24 Sep 2014 22:02:15 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 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 :content-type; bh=Q3rPUiGNPQAm7wlk5iEa+nOynoiaB/muvtP7IAXQMiE=; b=hUT8uLKBnqAAtfv1hSjhwIy4ZM7/yKXmp98lCWTdu2TbMqO/HmgdPzsTtxqMG0yiZu U4CeXNbGYKMAsWGmzi4uMj8zz8sBZD2dPZxdtsPnSS8UQ+GmHO7sfwg1L/sz+Ovxsre9 Po9om7aOk3sorPgQVwUvbr3yLb28cRhhdimLh6DrXBURh8+78J2kvku/4oqrDSrVV3eS 7AV2C02OADscddRf27Tse+/341Q3HZX1COlJolNKawItfCw910ru7nfyv//ZxBpB56wA mVvVicX8UfWrKvWL2MrYVRmtUq0wUxlBwSvMzrebE+49/aAd+HgH4pCjY+YAijKlm9e8 XzOw== MIME-Version: 1.0 X-Received: by 10.50.112.67 with SMTP id io3mr16717119igb.37.1411596133863; Wed, 24 Sep 2014 15:02:13 -0700 (PDT) In-Reply-To: <20140924152625.73dfa6d9@pwslap01u.europe.root.pri> References: <20140924152625.73dfa6d9@pwslap01u.europe.root.pri> Date: Thu, 25 Sep 2014 00:02:13 +0200 Message-ID: Subject: Re: Surprising parsing result with anonymous functions and for loops From: Mikael Magnusson To: zsh workers Content-Type: text/plain; charset=UTF-8 On 24 September 2014 16:26, Peter Stephenson wrote: > On Wed, 24 Sep 2014 16:07:36 +0200 > Mikael Magnusson wrote: >> I haven't looked at the parsing for the anonymous function stuff, but >> if it's not too hairy to fix, my vote is we drop this easter egg at >> some point. > > Unfortunately I think defining functions without braces is part of the > standard, though little used these days. This would have to be a > special case for anonymous functions, which is less useful. > > pws Yes, I'm aware of that, and it's not a problem at all for normal functions; % foo() for a { echo $a } ls zsh: parse error near `ls' Just in case something is unclear, let me try and clarify. % () echo inside the function; echo outside the function inside the function outside the function % foo () echo defining the function, $@; foo calling the function defining the function, calling the function The above two are perfectly okay. Now let's see when there's no function involved, % for a (foo bar) { echo $a } foo bar % for a (foo bar) { echo $a } bing baz zsh: correct 'bing' to 'big' [nyae]? n zsh: parse error near `bing' Okay, so an anonymous function without braces should not possibly be able to take arguments, because they are either part of the single command in the function, or if you have a ;, they are not part of the function definition at all. And writing anything after the end of a for loop without a separator is also clearly a syntax error. Now comes the surprising part again and hopefully this time it is surprising, % () for a { echo $a } bing baz zsh: correct 'bing' to 'big' [nyae]? n bing baz And again, just to clarify, this is still correctly rejected: % foo () for a { echo $a } bing baz zsh: correct 'bing' to 'big' [nyae]? n zsh: parse error near `bing' -- Mikael Magnusson