gawk doc error - awk eval error

This is a discussion on gawk doc error - awk eval error within the awk forums in Programming Languages category; gawk doc error - awk eval error what was a simple gawk doc error lead to a serious awk arg evaluation error in awk/gawk but Not in mawk the 1999 gawk.hlp or latest gawk.html http://www.weihenstephan.de/~syring/...nxUtilsHlp.zip http://www.gnu.org/software/gawk/manual/ say in section: 'Calling Built-in Functions' i=5; j=atan2(i++, i *= 2) "If the order of evaluation is left to right, then i first becomes six, and then 12, and atan2 is called with the two arguments six and 12. But if the order of evaluation is right to left, i first becomes 10, and then 11, and atan2 is called with the two arguments ...

Go Back   Application Development Forum > Programming Languages > awk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 09-04-2008, 07:13 PM
nt4-ever
Guest
 
Default gawk doc error - awk eval error

gawk doc error - awk eval error
what was a simple gawk doc error lead to a serious awk
arg evaluation error in awk/gawk but Not in mawk

the 1999 gawk.hlp or latest gawk.html
http://www.weihenstephan.de/~syring/...nxUtilsHlp.zip
http://www.gnu.org/software/gawk/manual/
say in section: 'Calling Built-in Functions'
i=5; j=atan2(i++, i *= 2)
"If the order of evaluation is left to right, then i first becomes
six, and then 12, and atan2 is called with the two arguments
six and 12. But if the order of evaluation is right to left, i first
becomes 10, and then 11, and atan2 is called with the two
arguments 11 and 10."

since i++ yields value of i and then incs i, statement should be:
'called with arguments five and 12' 'or 10 and 10' ???

try a simple
BEGIN{i=5;x=atan2(i++,i*=2);print(atan2(5,12),i,x) }
all three awk/gawk/mawk print:
0.394791 12 0.394791
that is they do left to right arg evaluation.

to see the difference between i++ and ++i try:
BEGIN{i=5;x=atan2(++i,i*=2);print(atan2(6,12),atan 2(12,12),i,x)}
awk/gawk printed:
0.463648 0.785398 12 0.785398
whereas mawk printed:
0.463648 0.785398 12 0.463648

since ++i should yield six and then i*2 yield 12
is not the awk/gawk return of atan2(12,12)
a serious arg evaluation error ???

:rod-t

princeton awk from:
http://www.cs.princeton.edu/~bwk/btl.mirror/
or http://gnuwin32.sourceforge.net/packages/nawk.htm
(foobar -- does Not require msvcrt.dll Nor msvcp60.dll)

gnu gawk from:
http://gnuwin32.sourceforge.net/packages/gawk.htm
or http://www.gnu.org/software/gawk/gawk.html

mawk (Ported to Win32 by O. Schoenfeldt) from:
http://www.klabaster.com/freeware.htm
(Very fast)
or http://gnuwin32.sourceforge.net/packages/mawk.htm
(foobar again: only needs msvcrt.dll; 2X slower than
Schoenfeldt's and has no system() nor pipes | ???)

errata:
a gui awk: http://jackparke.googlepages.com/awkgui
awk for parallel processors: http://www.parallel-awk.org/
Reply With Quote
  #2  
Old 09-04-2008, 09:46 PM
Anton Treuenfels
Guest
 
Default Re: gawk doc error - awk eval error


"nt4-ever" <nt4-ever@hotmail.com> wrote in message
news:db77c959-f65c-48ef-a673-56db3aaeb237@25g2000hsx.googlegroups.com...
> gawk doc error - awk eval error
> what was a simple gawk doc error lead to a serious awk
> arg evaluation error in awk/gawk but Not in mawk
>
> the 1999 gawk.hlp or latest gawk.html
> http://www.weihenstephan.de/~syring/...nxUtilsHlp.zip
> http://www.gnu.org/software/gawk/manual/
> say in section: 'Calling Built-in Functions'
> i=5; j=atan2(i++, i *= 2)
> "If the order of evaluation is left to right, then i first becomes
> six, and then 12, and atan2 is called with the two arguments
> six and 12. But if the order of evaluation is right to left, i first
> becomes 10, and then 11, and atan2 is called with the two
> arguments 11 and 10."
>
> since i++ yields value of i and then incs i, statement should be:
> 'called with arguments five and 12' 'or 10 and 10' ???


If we were talking about the 'C' programming language this would be called
"undefined behavior" by the language standard due to the lack of a sequence
point during the evaluation of function arguments which have side effects. A
'C' compiler can do anything at all in this case, including giving a wrong
answer or erasing all the files on your hard drive, and still be a
conforming implementation.

IMHO you are being unreasonable to expect identical behavior from all
AWK/NAWK/MAWK implementations when using function arguments which have side
effects. Don't do that, or rather don't expect the writers of these
wonderful free tools to stay up nights trying to make sure they work
identically in the face of whatever abuse someone might subject them to.

If you must have identical behavior then before the function call calculate
the expressions with side effects in the order you want them evaluated and
assign the results to variables that you then use as the function arguments.

Meet the tool-makers halfway here; this is not a great inconvenience. Or I
suppose you could always write your own tool that always behaves the way you
want, but that seems like a lot more work to me.

- Anton Treuenfels


Reply With Quote
  #3  
Old 09-05-2008, 04:01 AM
pk
Guest
 
Default Re: gawk doc error - awk eval error

On Friday 5 September 2008 03:46, Anton Treuenfels wrote:

>
> "nt4-ever" <nt4-ever@hotmail.com> wrote in message
> news:db77c959-f65c-48ef-a673-56db3aaeb237@25g2000hsx.googlegroups.com...
>> gawk doc error - awk eval error
>> what was a simple gawk doc error lead to a serious awk
>> arg evaluation error in awk/gawk but Not in mawk
>>
>> the 1999 gawk.hlp or latest gawk.html
>> http://www.weihenstephan.de/~syring/...nxUtilsHlp.zip
>> http://www.gnu.org/software/gawk/manual/
>> say in section: 'Calling Built-in Functions'
>> i=5; j=atan2(i++, i *= 2)
>> "If the order of evaluation is left to right, then i first becomes
>> six, and then 12, and atan2 is called with the two arguments
>> six and 12. But if the order of evaluation is right to left, i first
>> becomes 10, and then 11, and atan2 is called with the two
>> arguments 11 and 10."
>>
>> since i++ yields value of i and then incs i, statement should be:
>> 'called with arguments five and 12' 'or 10 and 10' ???

>
> If we were talking about the 'C' programming language this would be called
> "undefined behavior" by the language standard due to the lack of a
> sequence point during the evaluation of function arguments which have side
> effects. A 'C' compiler can do anything at all in this case, including
> giving a wrong answer or erasing all the files on your hard drive, and
> still be a conforming implementation.


At least in the case of arithmetic functions like atan2, that seems to hold
true for awk too:

"The arithmetic functions, except for int, shall be based on the ISO C
standard (see Concepts Derived from the ISO C Standard). The behavior is
undefined in cases where the ISO C standard specifies that an error be
returned or that the behavior is undefined."

Reply With Quote
  #4  
Old 09-17-2008, 12:23 AM
nt4-ever
Guest
 
Default Re: gawk doc error - awk eval error

thanks for your pedantic response;
just hope they do not use the atan2
function in calulating your academic
pay raise ..
Reply With Quote
  #5  
Old 09-17-2008, 03:34 AM
pk
Guest
 
Default Re: gawk doc error - awk eval error

On Wednesday 17 September 2008 06:23, nt4-ever wrote:

> thanks for your pedantic response;
> just hope they do not use the atan2
> function in calulating your academic
> pay raise ..


That was not "my" pedantic answer, but I just pasted what the standard says.
And, they can of course use the atan2 function to calculate anything. The
problem is not in the function, but in the way you call it. If you trigger
undefined behavior, then you'll have problems, and not only with the atan2
function.

Reply With Quote
  #6  
Old 09-18-2008, 01:14 AM
Anton Treuenfels
Guest
 
Default Re: gawk doc error - awk eval error


"nt4-ever" <nt4-ever@hotmail.com> wrote in message
news:fea39774-7b9f-4cab-a3c9-29931b5fa170@i20g2000prf.googlegroups.com...
> thanks for your pedantic response;
> just hope they do not use the atan2
> function in calulating your academic
> pay raise ..


The reponse may be canned, pedantic, and the standard reply of unenlightened
minds to the mighty freethinkers who dare to reveal to us how shaky in
reality our supposedly firm foundations are.

But.

You don't display even the least understanding of the reply you despise so
much. It seems instead that you would like us to agree with you that the
tool is broken.Which suggests that all you really know is that you don't
always get the answer you expect from atan2().

So I'll put it this way: the tool is not broken. You are using it
incorrectly. Although you still don't seem to realize it, your fundamental
abuse potentially affects every function, not just the atan2() function. You
will hurt yourself if you keep this up. If you learn to use the tool
correctly the "problem" will go away, and you can use it safely and with
confidence.

- Anton Treuenfels


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 06:41 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.