From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17239 invoked by alias); 19 Dec 2014 05:17:00 -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: 19587 Received: (qmail 12173 invoked from network); 19 Dec 2014 05:16:48 -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,HTML_MESSAGE, 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:cc:content-type; bh=+qA+/JRQIIiiynM8TVanQub+01ICC4V5ziNrNAcTl7I=; b=WgDgO0Svyr9aHqQm23/bFZBxu90xxlmd+qhVQRQHBHv8bvcxeVLhiHYxnFKpwdLs2M jSHgrv6c/O85yON6BMgNZYIPrNP7xQpIXpr+3+Gldmf7rcemjXZhLZM6txMNuJaZQFLA n7vfOwi8MVZCdEJS8xP+GxNSwOmsPOHn23dwVlcvHvpnVCUAQH3BONgAvhnEf0EPDLiC cL1bN5wlcbMe8r+3j4GOETd4LggH8zgCJ0R9iXlwQYTXYVp3X4wXXZFLamYCCYe0NIw/ kQ/9POIIF6W4OKgSYhFvQhbGHoEEZgzY00WSzhN2ZKYmu2dMbymapElNY6F1b8OMETEe PnaQ== X-Gm-Message-State: ALoCoQneCg61KIzGeTBeki62J4+zYp+5oUSEA3hBBMcy1C6INhdrji4gSM3IL6aHiTlETazfqCaE MIME-Version: 1.0 X-Received: by 10.152.3.100 with SMTP id b4mr5652563lab.68.1418966201654; Thu, 18 Dec 2014 21:16:41 -0800 (PST) In-Reply-To: <54939F50.50102@gmx.com> References: <54939F50.50102@gmx.com> Date: Thu, 18 Dec 2014 21:16:41 -0800 Message-ID: Subject: Re: Could someone clarify how math functions work? From: Kurtis Rader To: Eric Cook Cc: Zsh Users Content-Type: multipart/alternative; boundary=089e0149406465f59a050a8ad08d --089e0149406465f59a050a8ad08d Content-Type: text/plain; charset=UTF-8 I tried many variations on your example. None of them resulted in the output you and I would have expected based on the documentation. I conclude that either the documentation is wrong (at best confusing) or the implementation is broken. This is yet another example for why I use any language but a classic UNIX shell for any non-trivial behavior. This problem isn't unique to zsh. It affects most UNIX command shells (e.g., ksh, csh, etc.) to some degree. I say this as a 50+ year old grey-beard who has mastered and forgotten more languages and command shells (including non-UNIX varieties) than I can remember. UNIX style command shells derived from the Bourne shell (which includes zsh) have behaviors that are both difficult to document clearly and understand. This is a consequence of the complex interaction between parsing and evaluating statements. Not to mention changes in behavior based on various "backward compatibility" options that can be set at run time (as opposed to compile time). Not to mention those options were likely set far removed from your shell script (e.g., the ~/.zshrc or ~/.zshenv files). On Thu, Dec 18, 2014 at 7:45 PM, Eric Cook wrote: > > In the `functions -M' section of zshbuiltins there is the sentence: > "The result of the last arithmetical expression evaluated inside the > shell function (even if it is a form that normally only returns a > status) gives the result of the mathematical function." > > but: > 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 > > where as: > zsh -c 'add() { local arg n; for arg; do (( n += arg )); done; print n: > $n }; functions -M add; print results: $(( add(1,2,3) ))' > > Outputs: > n: 6 > results: 6 > > Is that expected behavior? If so, could you explain why? > -- Kurtis Rader Caretaker of the exceptional canines Junior and Hank --089e0149406465f59a050a8ad08d--