From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18232 invoked by alias); 25 Sep 2014 05:59:38 -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: 33240 Received: (qmail 6856 invoked from network); 25 Sep 2014 05:59:37 -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.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=1xOWQb7Zw8mktTBXpoRnWv0c6VXpmwJIHIkVIob0yqI=; b=isPckaS+JqLk0O/AQktHzgc6DO5ejp27brfRZeCOPFOtMYtNj5HVB+S8mdrH1K6oa+ n/gtk2kYHC0qdffiRxwC1RMiHX5tJn/newBadJvc7s3xIvqPs8+12xZYIBnuLgU1vFNT NZPOWYGot/bxm8WwA0DnJhti5O+yRjyzlr89yWCRaJ7MNZ/H5V2XUl6eHFtTa+2inNYr xxhZxi2NChKc5ik2vJrebvmOgLYBb0yF2LSz+t3O6rGG1/eSN5Vs02xzJvnWe/wfK87x XEQYjnat9nDzZqPIOuaHk5s4cP7H47Ol48vM54KdXDPaDfQYEEll1Hkd5HIRYZBuMarR jdqw== X-Gm-Message-State: ALoCoQmHdAfU2O8+F8if44TduVkEP4F4XXI6+f/0i62dQTr59lFTtuTFFIDqI0e/D31NAxXvfDMK MIME-Version: 1.0 X-Received: by 10.180.221.107 with SMTP id qd11mr16321372wic.61.1411623326219; Wed, 24 Sep 2014 22:35:26 -0700 (PDT) In-Reply-To: References: <20140924152625.73dfa6d9@pwslap01u.europe.root.pri> Date: Wed, 24 Sep 2014 22:35:26 -0700 Message-ID: Subject: Re: Surprising parsing result with anonymous functions and for loops From: Bart Schaefer To: zsh workers Content-Type: text/plain; charset=UTF-8 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.