From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18411 invoked by alias); 25 Sep 2014 10:03:12 -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: 33241 Received: (qmail 5011 invoked from network); 25 Sep 2014 10:03:01 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=RwI/o1e7jFihc1mx0xfKfQomqSpgaJ4nqvTy5hLFpSg=; b=IudhYU5hcmsuygh1juPoJ4FxroRYZGy7NKC8EZnRWxuSY6Oo3LCJpp444AADqBuhn/ VKenABeqKxPLJNbKQuesfTrigEsEaA4zsd9mD20GWd+E7XBkyfXarfma7MW9CwJJxSBL 20qjD1dv2nxmeLuEv5YGx4pb1ji8Z5SiRLbowYIeGwQNh8HFQMbWhmMTP8qdJ86/UWyT Miq8zCazUVJALFcJrXv67MXeBa3sYX2CH10jytcRjAr5K6XNoNumpJ5itJ7x6EkOcWOG KBIueQBojhF5VPrg2Cx+heOarzXOdilsQN4EpFpRUYFN6+oyAuVoK0vVaiph6r5+whvl 9ASA== MIME-Version: 1.0 X-Received: by 10.50.138.194 with SMTP id qs2mr3291521igb.4.1411639375353; Thu, 25 Sep 2014 03:02:55 -0700 (PDT) In-Reply-To: References: <20140924152625.73dfa6d9@pwslap01u.europe.root.pri> Date: Thu, 25 Sep 2014 12:02:55 +0200 Message-ID: Subject: Re: Surprising parsing result with anonymous functions and for loops From: Mikael Magnusson To: Bart Schaefer Cc: zsh workers Content-Type: text/plain; charset=UTF-8 On 25 September 2014 07:35, Bart Schaefer wrote: > On Wed, Sep 24, 2014 at 3:02 PM, Mikael Magnusson wrote: >> >> 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. > > That's not quite how it works. The foo() case is a function > definition, but the "anonymous" case is simultaneously a definition > and a call. In the latter situation, the parser consumes a valid > function definition, and then anything left over is its arguments. > Since "for a { echo $a }" is a valid function body, the parse switches > to looking for arguments after that point. In the former case, there > is no implicit function call, so it is an error for anything to be > left over. > > The presence of braces around the entire body simply allows the parser > to distinguish the body from the arguments. If there are other > syntactic clues, those also distinguish body from arguments, e.g., the > token "done" here: > > () for a; do echo $a; done bing bong > > Note that the semicolons didn't terminate the function definition, > because they are part of the for-do-done compound syntax. Okay, but does anyone at least agree that doing alias expansion at that point is highly surprising? -- Mikael Magnusson