Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Surprising parsing result with anonymous functions and for loops
- X-seq: zsh-workers 33237
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh workers <zsh-workers@xxxxxxx>
- Subject: Re: Surprising parsing result with anonymous functions and for loops
- Date: Thu, 25 Sep 2014 00:02:13 +0200
- 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==
- In-reply-to: <20140924152625.73dfa6d9@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAHYJk3SXb_hgz-abLaoLeU=U-Y0zwm=vHv-o+Oeg6=C3CedjUQ@mail.gmail.com> <20140924152625.73dfa6d9@pwslap01u.europe.root.pri>
On 24 September 2014 16:26, Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Wed, 24 Sep 2014 16:07:36 +0200
> Mikael Magnusson <mikachu@xxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author