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

Re: Infinite recursions in math evaluation



On May 13, 11:37pm, Mikael Magnusson wrote:
}
} [...]  Aha, actually a=a; $(( a )) crashes in the same way. (On
} a machine with a presumably less optimized/buggy compile, it does
} print "zsh: math recursion limit exceeded" instead of crashing). Is it
} simply a user error? I wouldn't expect either of these expressions to
} recursively look up values of the parameter until it encountered a
} number, but this is indeed what happens:
} % a=b; b=c; c=d; d=e; e=f; f=5; echo $(( a ))
} 5
} bash does the same...
} 
} I scanned quickly through the "Arithmetic Evaluation" section and
} found nothing suggesting that this should happen.

It's implicit in this:

    Named parameters and subscripted arrays can be referenced by name
    within an arithmetic expression without using the parameter expansion
    syntax.  For example,

        ((val2 = val1 * 2))

    assigns twice the value of $val1 to the parameter named val2.

"The value of $val1" in an arithmetic context is the result of doing
arithmetic evaluation on whatever is stored in the parameter.  If
that's the name of another (or even the same) parameter, then ...



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