Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: syntax error with anonymous functions when an argument begins with (
- X-seq: zsh-workers 29632
- From: Jilles Tjoelker <jilles@xxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: syntax error with anonymous functions when an argument begins with (
- Date: Sun, 31 Jul 2011 16:17:15 +0200
- 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
> [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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author