From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 11313 invoked by alias); 19 Dec 2014 09:36:02 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19608 Received: (qmail 9853 invoked from network); 19 Dec 2014 09:35:59 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7fc86d0000066b7-f7-5493f17be540 Date: Fri, 19 Dec 2014 09:35:51 +0000 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: Could someone clarify how math functions work? Message-id: <20141219093551.5a89e4d9@pwslap01u.europe.root.pri> In-reply-to: <54939F50.50102@gmx.com> References: <54939F50.50102@gmx.com> Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrKLMWRmVeSWpSXmKPExsVy+t/xa7rVHyeHGKxdYWWx4+RKRgdGj1UH PzAFMEZx2aSk5mSWpRbp2yVwZRydFVywmqPi9MJnrA2MR9i6GDk5JARMJNZ/XsQMYYtJXLi3 HijOxSEksJRRYuvRXUwQziImiR0Xe9ghnG2MEq9etzCCtLAIqErc+3QDrJ1NwFBi6qbZYHER AVGJ5Ss2s4PYwgLWElvmXQBbxytgL/Hy7Q6wek6g3l/7f7CC2EICKhLPX/xnArH5BfQlrv79 xARxkr3EzCtnGCF6BSV+TL7HAmIzC2hJbN7WxAphy0tsXvOWGWKOusSNu7vZJzAKzULSMgtJ yywkLQsYmVcxiqaWJhcUJ6XnGukVJ+YWl+al6yXn525ihATt1x2MS49ZHWIU4GBU4uH90Dg5 RIg1say4MvcQowQHs5IIr+NxoBBvSmJlVWpRfnxRaU5q8SFGJg5OqQbG9pdn7totkjbt+Lz7 vunNGS6FNQUT6msX7H+l5NZ8Tvn6gTAxycN2nSePXL6r7vvHqdX6jfqSKkU2/l+FNvFthuZP TNZvPD1j4xThpP1+NZusryY/vVLhkzeBW9h1t1OvH+v3yxfjQwIPB/w1uG5qLlWgYW+3uMDA 1zH6VsCH1I2BFvxcdueUWIozEg21mIuKEwH6MBTeOAIAAA== On Thu, 18 Dec 2014 22:45:20 -0500 Eric Cook wrote: > zsh -c 'add() ( for arg; do (( n += arg )); done; print n: $n ); > functions -M add; print results: $(( add(1,2,3) ))' > > Outputs: > n: 6 > results: 3 This is all sorted out --- the ( ... ) runs in a subshell and the value the math function has access to is the last value in the main shell --- but I'm scratching my head at how we explain this sort of thing better. It's just the kind of problem Ray has been banging his head against and why Kurtis, correctly in my opinion, suggests something other than a shell for a lot of programming tasks. I'm wondering, however, if we can do a bit better by strengthening the warnings against variant syntax --- whose sole role appears to be to confuse the user --- and provide some kind of good practice guide for complex syntax such as functions, loops, etc. But would anyone read it? One of the problems with the documentation is there's too much of it, measured by volume of text rather than by desired effect. Sigh. pws