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 33241
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Surprising parsing result with anonymous functions and for loops
- Date: Thu, 25 Sep 2014 12:02:55 +0200
- Cc: zsh workers <zsh-workers@xxxxxxx>
- 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=RwI/o1e7jFihc1mx0xfKfQomqSpgaJ4nqvTy5hLFpSg=; b=IudhYU5hcmsuygh1juPoJ4FxroRYZGy7NKC8EZnRWxuSY6Oo3LCJpp444AADqBuhn/ VKenABeqKxPLJNbKQuesfTrigEsEaA4zsd9mD20GWd+E7XBkyfXarfma7MW9CwJJxSBL 20qjD1dv2nxmeLuEv5YGx4pb1ji8Z5SiRLbowYIeGwQNh8HFQMbWhmMTP8qdJ86/UWyT Miq8zCazUVJALFcJrXv67MXeBa3sYX2CH10jytcRjAr5K6XNoNumpJ5itJ7x6EkOcWOG KBIueQBojhF5VPrg2Cx+heOarzXOdilsQN4EpFpRUYFN6+oyAuVoK0vVaiph6r5+whvl 9ASA==
- In-reply-to: <CAH+w=7ZOaTpcsQY+Kt5hnDr218LOfmz21Xp1-rZqnaD0zbS0Zg@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> <20140924152625.73dfa6d9@pwslap01u.europe.root.pri> <CAHYJk3TR=EaB2yOTO_ZDGtnxrPatUNoj4CrG2SMy62vooLaUeA@mail.gmail.com> <CAH+w=7ZOaTpcsQY+Kt5hnDr218LOfmz21Xp1-rZqnaD0zbS0Zg@mail.gmail.com>
On 25 September 2014 07:35, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Wed, Sep 24, 2014 at 3:02 PM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>>
>> 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.
>
> That's not quite how it works. The foo() case is a function
> definition, but the "anonymous" case is simultaneously a definition
> and a call. In the latter situation, the parser consumes a valid
> function definition, and then anything left over is its arguments.
> Since "for a { echo $a }" is a valid function body, the parse switches
> to looking for arguments after that point. In the former case, there
> is no implicit function call, so it is an error for anything to be
> left over.
>
> The presence of braces around the entire body simply allows the parser
> to distinguish the body from the arguments. If there are other
> syntactic clues, those also distinguish body from arguments, e.g., the
> token "done" here:
>
> () for a; do echo $a; done bing bong
>
> Note that the semicolons didn't terminate the function definition,
> because they are part of the for-do-done compound syntax.
Okay, but does anyone at least agree that doing alias expansion at
that point is highly surprising?
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author