zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: zsh workers <zsh-workers@zsh.org>
Subject: Re: Surprising parsing result with anonymous functions and for loops
Date: Thu, 25 Sep 2014 00:02:13 +0200	[thread overview]
Message-ID: <CAHYJk3TR=EaB2yOTO_ZDGtnxrPatUNoj4CrG2SMy62vooLaUeA@mail.gmail.com> (raw)
In-Reply-To: <20140924152625.73dfa6d9@pwslap01u.europe.root.pri>

On 24 September 2014 16:26, Peter Stephenson <p.stephenson@samsung.com> wrote:
> On Wed, 24 Sep 2014 16:07:36 +0200
> Mikael Magnusson <mikachu@gmail.com> 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


  reply	other threads:[~2014-09-24 22:02 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 [this message]
2014-09-25  5:35     ` Bart Schaefer
2014-09-25  5:53       ` Bart Schaefer
2014-09-25 10:02       ` Mikael Magnusson
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='CAHYJk3TR=EaB2yOTO_ZDGtnxrPatUNoj4CrG2SMy62vooLaUeA@mail.gmail.com' \
    --to=mikachu@gmail.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).