From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11138 invoked by alias); 24 Sep 2014 19:14:51 -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: 33236 Received: (qmail 27691 invoked from network); 24 Sep 2014 19:14:40 -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,HTML_MESSAGE,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=cacu0YSk0q7Nf1XrJPDQj+0XzD+YKkQcLWf3hjH1flM=; b=lcUAqmgyiP1IZYmv8NS4G+mVkZjiXlc62sXUL8iecBgOANDm8ZgbaMOqaZBVNz26yM qEW2j4BxqSG4BKwTPud1VtajiM8N7eVhEyQNKixdUdGY6U071fVLVymNX+DkTluocGmC UTQg1Fps0eF9E0Pc1NjHVx8F01aoe7WNTj/tuevZj8j9eOB9KHhVESaIZ9apG20mNc1O FannOC0hBXQOHT6iXTOUXx6n+moW9oG5k9VBDOUgbr9vggipqInH9O2B2ylJuqzrQ3Ka WVk45sLV9Vf4T1rQGBiq37zjAbWJHVehGv4S+HZWhmo9AFTz9KhimyDC8tyrnTnSYsDR TwDQ== MIME-Version: 1.0 X-Received: by 10.50.27.4 with SMTP id p4mr15275367igg.1.1411586078954; Wed, 24 Sep 2014 12:14:38 -0700 (PDT) In-Reply-To: References: Date: Wed, 24 Sep 2014 15:14:38 -0400 Message-ID: Subject: Fwd: Surprising parsing result with anonymous functions and for loops From: Clint Hepner To: zsh-workers@zsh.org Content-Type: multipart/alternative; boundary=047d7b111777ce5f4c0503d47e35 --047d7b111777ce5f4c0503d47e35 Content-Type: text/plain; charset=UTF-8 I meant to reply to the list, but only replied to Mikael instead. ---------- Forwarded message ---------- From: Clint Hepner Date: Wed, Sep 24, 2014 at 3:11 PM Subject: Re: Surprising parsing result with anonymous functions and for loops To: Mikael Magnusson The POSIX standard defines a function definition as () 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 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 > --047d7b111777ce5f4c0503d47e35--