Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: arithmetic operator precedence
- X-seq: zsh-workers 25200
- From: Vincent Lefevre <vincent@xxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: Re: arithmetic operator precedence
- Date: Tue, 17 Jun 2008 17:05:54 +0200
- Cc: Richard Hartmann <richih.mailinglist@xxxxxxxxx>, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- In-reply-to: <20080617143559.GP5016@xxxxxxxxxxxxxxx>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxxxxx>, Richard Hartmann <richih.mailinglist@xxxxxxxxx>, Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
- References: <20080616144211.276fb0e3@pws-pc> <2d460de70806170219k12ff4cadn441b52c48bf8076f@xxxxxxxxxxxxxx> <20080617094509.GC5016@xxxxxxxxxxxxxxx> <20080617111934.GE10734@xxxxxxxxxxxxxxxxxxx> <20080617115742.GE5016@xxxxxxxxxxxxxxx> <20080617123551.GJ10734@xxxxxxxxxxxxxxxxxxx> <20080617124607.GH5016@xxxxxxxxxxxxxxx> <20080617130246.GL10734@xxxxxxxxxxxxxxxxxxx> <20080617132039.GK5016@xxxxxxxxxxxxxxx> <20080617143559.GP5016@xxxxxxxxxxxxxxx>
On 2008-06-17 15:35:59 +0100, Stephane Chazelas wrote:
> It can't be that simple though, as in
>
> x=-1; $((1 x))
>
> which would be POSIX but fails in all shells.
No, $((1 x)) is an invalid expression (unless the shell sees this
as an extension), so POSIX requires it to fail.
This is different from $((1 $x)), where the expansion of $x occurs
first.
> Or
>
> x=1; $((x = 1 + x))
>
> which obviously is not meant to be the same as $(($x = 1 + $x))
So? What's the problem with them not being the same?
Note that POSIX says:
The shell shall expand all tokens in the expression for parameter
^^^^^^^^^
expansion, command substitution, and quote removal.
^^^^^^^^^
Next, the shell shall treat this as an arithmetic expression
^^^^
In the first case, the expression is x = 1 + x. In the second case,
it is 1 = 1 + 1.
> So that
>
> If the shell variable x contains a value that forms a valid
> integer constant, then the arithmetic expansions "$((x))" and
> "$(($x))" shall return the same value.
>
> says either too little or too much to be useful.
I agree that this isn't perfect (BTW, see my mail in the Austin group
when it appears -- I haven't received a copy yet).
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.org/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.org/blog/>
Work: CR INRIA - computer arithmetic / Arenaire project (LIP, ENS-Lyon)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author