Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Could someone clarify how math functions work?

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.


Messages sorted by: Reverse Date, Date, Thread, Author