zsh-workers
 help / color / mirror / code / Atom feed
From: Jilles Tjoelker <jilles@stack.nl>
To: zsh-workers@zsh.org
Subject: Re: syntax error with anonymous functions when an argument begins with (
Date: Sun, 31 Jul 2011 16:17:15 +0200	[thread overview]
Message-ID: <20110731141715.GA66652@stack.nl> (raw)

> [people want stuff like () { echo yay } (a|b)]

In fact, the closing brace may validly be followed by certain keywords
in older zsh, for example

  if :; then () { echo hi; } else () { echo bye; } fi

prints "hi" in zsh 4.3.12 from FreeBSD ports.

If a regular function definition is used, like

  if :; then f() { echo hi; } else f() { echo bye; } fi; f

then the construct is POSIX compliant and works in all shells I tried
(not including patched versions of zsh).

The same applies if the function definition contains a different kind of
compound command such as if, which is unusual but POSIX compliant and
portable. For example, between two "fi" keywords a space suffices.

(On the other hand, if another command follows, such as ... fi; if ...,
a separator is required.)

So I think that unfortunately passing arguments to anonymous functions
requires an uglier syntax to avoid breaking compatibility. In any case,
placing a keyword after a closing brace that is not an anonymous
function's main command is valid and should be recognized as such.

-- 
Jilles Tjoelker


             reply	other threads:[~2011-07-31 14:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-31 14:17 Jilles Tjoelker [this message]
2011-07-31 18:39 ` Peter Stephenson
2011-08-08  4:29   ` Mikael Magnusson
2011-08-08  8:34     ` Peter Stephenson
2011-08-08  8:40       ` Mikael Magnusson
  -- strict thread matches above, loose matches on Subject: below --
2011-07-27 16:48 Mikael Magnusson
2011-07-27 19:22 ` Peter Stephenson

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=20110731141715.GA66652@stack.nl \
    --to=jilles@stack.nl \
    --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).