zsh-workers
 help / color / mirror / code / Atom feed
* syntax error with anonymous functions when an argument begins with (
@ 2011-07-27 16:48 Mikael Magnusson
  2011-07-27 19:22 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Mikael Magnusson @ 2011-07-27 16:48 UTC (permalink / raw)
  To: zsh workers

% () { echo yay } hello (a|b)
zsh: parse error near `('
% () { echo yay } (a|b)
zsh: parse error near `('
% () { echo yay } .(#c0)(a|b)
yay
% () { echo yay } ./(a|b)
yay

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: syntax error with anonymous functions when an argument begins with (
@ 2011-07-31 14:17 Jilles Tjoelker
  2011-07-31 18:39 ` Peter Stephenson
  0 siblings, 1 reply; 7+ messages in thread
From: Jilles Tjoelker @ 2011-07-31 14:17 UTC (permalink / raw)
  To: zsh-workers

> [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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2011-08-08  8:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-07-27 16:48 syntax error with anonymous functions when an argument begins with ( Mikael Magnusson
2011-07-27 19:22 ` Peter Stephenson
2011-07-31 14:17 Jilles Tjoelker
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

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).