[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Arithmetic expression: evaluation order bug
From: |
Steffen Nurpmeso |
Subject: |
Re: Arithmetic expression: evaluation order bug |
Date: |
Fri, 30 Dec 2022 21:44:28 +0100 |
User-agent: |
s-nail v14.9.24-383-g2889cb06b9 |
Greg Wooledge wrote in
<Y64mrP9da/WgVEld@wooledge.org>:
|On Fri, Dec 30, 2022 at 12:21:52AM +0100, Steffen Nurpmeso wrote:
|> ..i want to reiterate the relation to what "human logic" expects.
|
|I'm a human, so I feel qualified to address this point.
|
|What I expect from a command like
|
|(( i += j += i += j ))
|
|is to get unpredictable results that have no relationship to anything
|useful, because that code is complete rubbish.
|
|I can't even guess what the *intent* of the code is.
This is from a test script (of course). "i += i += i += i" seems
to be equal to "i *= 8" or "i <<= 3" (of which only the second is
something that i can grasp at a glance .. unless in good shape).
Looking back, it arose out of the ashes of the test
s I1=10 I2=20;p "<$((I1+=I2+=I1))>";e "<$I1><$I2>"
which anything tested gets right. 'What tests are for. (Except
in the car industry but that is off-topic.)
By sheer luck many minds over several generations shared my point
of view regarding what the outcome has to be so that i do not feel
so lonely about it. Yeah, and it flows so much nicer.
i1 += i2 += i1 += i2
i1 += i2, i2 += i1, i1 += i2
Digital, logical, liberal, yuck :)
|I'm not optimistic enough to expect an error message, or even better,
|an immediate termination of the shell. That would be *far* too useful
|(because it would force the script's author to rewrite that code).
Well in real life i have not yet encountered a bug in bash; as in,
from working/"living" with it (for many years, all in all).
(Maybe multibyte problems in bash 2, but that was long ago, and
i am not even sure whether i relate that correctly. .inputrc
hate.)
Ciao,
--steffen
|
|Der Kragenbaer, The moon bear,
|der holt sich munter he cheerfully and one by one
|einen nach dem anderen runter wa.ks himself off
|(By Robert Gernhardt)
- Re: Arithmetic expression: evaluation order bug, (continued)
- Re: Arithmetic expression: evaluation order bug, Steffen Nurpmeso, 2022/12/29
- Re: Arithmetic expression: evaluation order bug, Andreas Schwab, 2022/12/29
- Re: Arithmetic expression: evaluation order bug, Steffen Nurpmeso, 2022/12/29
- Re: Arithmetic expression: evaluation order bug, Steffen Nurpmeso, 2022/12/29
- Re: Arithmetic expression: evaluation order bug, Steffen Nurpmeso, 2022/12/29
- Re: Arithmetic expression: evaluation order bug, Greg Wooledge, 2022/12/29
- Re: Arithmetic expression: evaluation order bug,
Steffen Nurpmeso <=
- Re: Arithmetic expression: evaluation order bug, Alain D D Williams, 2022/12/30
- Re: Arithmetic expression: evaluation order bug, Robert Elz, 2022/12/30
- Re: Arithmetic expression: evaluation order bug, Steffen Nurpmeso, 2022/12/30
- Re: Arithmetic expression: evaluation order bug, Robert Elz, 2022/12/30