[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Documentation

From: Manuel Collado
Subject: Re: [bug-gawk] Documentation
Date: Wed, 10 Dec 2014 11:35:39 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7

El 10/12/2014 2:36, Andrew J. Schorr escribió:
On Tue, Dec 09, 2014 at 02:35:28PM -0500, Teri Price wrote:
In section 9.1.1 of the documentation, there is an example that I think has
a mistake.
Here's the example:
i = 5
j = atan2(i++, i *= 2)

If the order of evaluation is left to right, then i first becomes 6, and
then 12, and atan2() is called with the two arguments 6 and 12. But if the
order of evaluation is right to left, i first becomes 10, then 11, and
atan2() is called with the two arguments 11 and 10.

And here's what I think it should be:

If the order is left to right, atan2 is called with 2 arguments 5 and 12
because i++ has the value of 5 even though i became 6.

If the order is right to left, i*=2 makes i 10 and then i++ still holds the
value 10, so the 2 arguments would be 10 and 10.

I think you are correct.  But isn't the simpler fix to replace "i++"
with "++i"? :-)

When calling a function, using expressions with side effects as arguments can be considered unsafe. At least if the evaluation of some argument affects the evaluation of others. To be safe you could write:

i = 5
a = i++
b = i *= 2
j = atan2(a, b)

Well, this is perhaps an academic point of view.

Manuel Collado - http://lml.ls.fi.upm.es/~mcollado

reply via email to

[Prev in Thread] Current Thread [Next in Thread]