Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Could someone clarify how math functions work?
- X-seq: zsh-users 19608
- From: Peter Stephenson <p.stephenson@xxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Could someone clarify how math functions work?
- Date: Fri, 19 Dec 2014 09:35:51 +0000
- In-reply-to: <54939F50.50102@gmx.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- Organization: Samsung Cambridge Solution Centre
- References: <54939F50.50102@gmx.com>
On Thu, 18 Dec 2014 22:45:20 -0500
Eric Cook <llua@xxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author