zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh workers <zsh-workers@zsh.org>
Subject: Re: Surprising parsing result with anonymous functions and for loops
Date: Thu, 25 Sep 2014 12:02:55 +0200	[thread overview]
Message-ID: <CAHYJk3TZat+YOyx6BDTBZHyqppRE=97vKaAw4z0nmu_4nTOB+A@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7ZOaTpcsQY+Kt5hnDr218LOfmz21Xp1-rZqnaD0zbS0Zg@mail.gmail.com>

On 25 September 2014 07:35, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Wed, Sep 24, 2014 at 3:02 PM, Mikael Magnusson <mikachu@gmail.com> 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


  parent reply	other threads:[~2014-09-25 10:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-24 14:07 Mikael Magnusson
2014-09-24 14:26 ` Peter Stephenson
2014-09-24 22:02   ` Mikael Magnusson
2014-09-25  5:35     ` Bart Schaefer
2014-09-25  5:53       ` Bart Schaefer
2014-09-25 10:02       ` Mikael Magnusson [this message]
2014-09-25 11:39         ` Peter Stephenson
2014-09-25 13:21           ` Mikael Magnusson
2014-09-25 13:52             ` Peter Stephenson
2014-09-26  8:58               ` Peter Stephenson
     [not found] ` <CAKjp4B7Gy9f2RCYzn8G6i+ADh_p7GWZEv1x_Cd0eR3Ggxv+APw@mail.gmail.com>
2014-09-24 19:14   ` Fwd: " Clint Hepner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3TZat+YOyx6BDTBZHyqppRE=97vKaAw4z0nmu_4nTOB+A@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).