From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19028 invoked by alias); 31 Jul 2011 14:26:14 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29632 Received: (qmail 28099 invoked from network); 31 Jul 2011 14:26:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.4 required=5.0 tests=BAYES_00,FAKE_REPLY_C autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at spf.stack.nl designates 131.155.140.104 as permitted sender) Date: Sun, 31 Jul 2011 16:17:15 +0200 From: Jilles Tjoelker To: zsh-workers@zsh.org Subject: Re: syntax error with anonymous functions when an argument begins with ( Message-ID: <20110731141715.GA66652@stack.nl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) > [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