Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Fwd: Surprising parsing result with anonymous functions and for loops
- X-seq: zsh-workers 33236
- From: Clint Hepner <clint.hepner@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Fwd: Surprising parsing result with anonymous functions and for loops
- Date: Wed, 24 Sep 2014 15:14:38 -0400
- 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=cacu0YSk0q7Nf1XrJPDQj+0XzD+YKkQcLWf3hjH1flM=; b=lcUAqmgyiP1IZYmv8NS4G+mVkZjiXlc62sXUL8iecBgOANDm8ZgbaMOqaZBVNz26yM qEW2j4BxqSG4BKwTPud1VtajiM8N7eVhEyQNKixdUdGY6U071fVLVymNX+DkTluocGmC UTQg1Fps0eF9E0Pc1NjHVx8F01aoe7WNTj/tuevZj8j9eOB9KHhVESaIZ9apG20mNc1O FannOC0hBXQOHT6iXTOUXx6n+moW9oG5k9VBDOUgbr9vggipqInH9O2B2ylJuqzrQ3Ka WVk45sLV9Vf4T1rQGBiq37zjAbWJHVehGv4S+HZWhmo9AFTz9KhimyDC8tyrnTnSYsDR TwDQ==
- In-reply-to: <CAKjp4B7Gy9f2RCYzn8G6i+ADh_p7GWZEv1x_Cd0eR3Ggxv+APw@mail.gmail.com>
- 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> <CAKjp4B7Gy9f2RCYzn8G6i+ADh_p7GWZEv1x_Cd0eR3Ggxv+APw@mail.gmail.com>
I meant to reply to the list, but only replied to Mikael instead.
---------- Forwarded message ----------
From: Clint Hepner <clint.hepner@xxxxxxxxx>
Date: Wed, Sep 24, 2014 at 3:11 PM
Subject: Re: Surprising parsing result with anonymous functions and for
loops
To: Mikael Magnusson <mikachu@xxxxxxxxx>
The POSIX standard defines a function definition as
<name> () <compound-statement>
where { ...; } is just one kind of compound statement, along with for
loops, while loops, etc. The following are all valid function definitions:
foo () { echo bar; }
foo () while [[ $i != foo ]]; do i=foo; done
foo () for i in 1 2 3; do echo $i; done
foo () ( echo bar; )
foo () (( x=3 ))
The man page is ambiguous about what constitutes a function; it lists three
allowable forms:
function word ... [ () ] [ term ] { list }
word ... () [ term ] { list }
word ... () [ term ] command
where the third is the one that describes the observed behavior. I thought
the first might imply
special behavior when using the function keyword, but
function foo (( x = 3))
works as well. The second is would seem to be a special case of the third,
except it does seem to treat the braces as part of the syntax:
foo () { echo foo }
would in POSIX require a semicolon prior to the closing brace, but works in
zsh.
On Wed, Sep 24, 2014 at 10:07 AM, Mikael Magnusson <mikachu@xxxxxxxxx>
wrote:
> The intended command was something along these lines:
> () { for a { echo $a } } some words here
> but I forgot the enclosing { } and wrote the following
> () for a { echo $a } some words here
> surely this doesn't work, right?... wrong:
> % () for a { echo $a } some words here
> some
> words
> here
>
> Perhaps even more surprising is the following:
> % () for a { echo $a } ls
> ls
> --color=auto
> -T
> 0
> -A
> -v
> --quoting-style=shell
>
> 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.
>
> --
> Mikael Magnusson
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author