WHINY_USERS=0

View: New views
10 Messages — Rating Filter:   Alert me  

WHINY_USERS=0

by Hermann Peifer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I was making some WHINY_USERS performance tests, following the example at http://awk.info/?tip/whinyUsers

It looks to me that not only WHINY_USERS=1, but also WHINY_USERS=0 or even WHINY_USERS=  are leading to sorted processing of arrays. I have to actually unset WHINY_USERS in order to get back to default array processing. The corresponding test in AWK source code (main.c) is:

        if (getenv("WHINY_USERS") != NULL)
                whiny_users = TRUE;

I am wondering if this is rather a feature or something else?

Regards, Hermann



Parent Message unknown Re: WHINY_USERS=0

by Aharon Robbins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Greetings. Re this:

> Date: Fri, 23 Oct 2009 19:41:26 +0200
> From: Hermann Peifer <peifer@...>
> To: bug-gawk@...
> CC: menzies.tim@...
> Subject: WHINY_USERS=0
>
> I was making some WHINY_USERS performance tests, following the example
> at http://awk.info/?tip/whinyUsers
>
> It looks to me that not only WHINY_USERS=1, but also WHINY_USERS=0 or
> even WHINY_USERS=  are leading to sorted processing of arrays. I have
> to actually unset WHINY_USERS in order to get back to default array
> processing. The corresponding test in AWK source code (main.c) is:
>
> if (getenv("WHINY_USERS") != NULL)
> whiny_users = TRUE;
>
> I am wondering if this is rather a feature or something else?
>
> Regards, Hermann

It's what programmer types call an "easter egg", meaning an undocumented
feature with unusual or interesting behavior, and I intend to keep it
that way (but see the gawk.texi file :-).

The feature as coded means "if WHINY_USERS exists in the environment,
enable the whiny user related features." (There are at least two.)

So, the behavior you're seeing is what I wanted.  I don't intend to
change it.

Personally, I think you should use asort or asorti if you want array
sorting. The code is much clearer that way.

Thanks,

Arnold



Re: WHINY_USERS=0

by John Cowan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Aharon Robbins scripsit:

> The feature as coded means "if WHINY_USERS exists in the environment,
> enable the whiny user related features." (There are at least two.)

Three, but I concede that I can't figure out how to trigger the third
use of the feature, which appears to print a warning that a file is
unopenable just before printing a fatal error that it's unopenable.

--
I now introduce Professor Smullyan,             John Cowan
who will prove to you that either               cowan@...
he doesn't exist or you don't exist,            http://www.ccil.org/~cowan
but you won't know which.                               --Melvin Fitting



Re: WHINY_USERS=0

by Hermann Peifer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Aharon Robbins wrote:

> It's what programmer types call an "easter egg", meaning an undocumented
> feature with unusual or interesting behavior, and I intend to keep it
> that way (but see the gawk.texi file :-).
>
> The feature as coded means "if WHINY_USERS exists in the environment,
> enable the whiny user related features." (There are at least two.)
>
> So, the behavior you're seeing is what I wanted.  I don't intend to
> change it.
>
> Personally, I think you should use asort or asorti if you want array
> sorting. The code is much clearer that way.

Aharon,

Thanks for the explanations, which confirms my observation that
WHINY_USERS=0 isn't enough to unset the variable.

About asort() and asorti(): I use these functions occasionally, but what
I actually need most are simply sorted *original* array indices (which
almost always have some meaning, like country code, or similar, so I
don't want to destroy them). IMO, there is nothing better and cleaner
than WHINY_USERS to achieve this gawk behaviour. The built-in asorti()
function forces me to copy src array into dest array in order to avoid
the loss of original indices. This makes the code more complicated, as I
see it.

Anyway: I actually didn't want to start a discussion here. Thanks again
for the WHINY_USERS easter egg!.

Hermann

PS for Tim: You might want to re-visit your WHINY_USERS performance test
described in http://awk.info/?tip/whinyUsers



Parent Message unknown Re: WHINY_USERS=0

by Hermann Peifer-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

John Cowan wrote:
> Aharon Robbins scripsit:
>
>> The feature as coded means "if WHINY_USERS exists in the environment,
>> enable the whiny user related features." (There are at least two.)
>
> Three, but I concede that I can't figure out how to trigger the third
> use of the feature, which appears to print a warning that a file is
> unopenable just before printing a fatal error that it's unopenable.
>

Trying to open a directory w/o WHINY_USERS, with gawk 3.1.7 -> fatal error

$ gawk '1' somedir/ somefile
gawk: cmd. line:1: fatal: cannot open file `somedir/' for reading (Success)


With WHINY_USERS, there is only a warning and processing continues
(somefile has only 1 record: Hello World)


$ WHINY_USERS=1 gawk '1' somedir/ somefile
gawk: cmd. line:1: warning: cannot open file `somedir/' for reading
(Success)
Hello World


Hope this helps, Hermann

Re: WHINY_USERS=0

by Andreas Schwab-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hermann Peifer <peifer@...> writes:

> $ gawk '1' somedir/ somefile
> gawk: cmd. line:1: fatal: cannot open file `somedir/' for reading (Success)

2009-10-26  Andreas Schwab  <schwab@...>

        * io.c (iop_open): Set errno when rejecting a directory.

--- io.c.~1.25.~ 2009-10-16 08:50:33.000000000 +0200
+++ io.c 2009-10-26 13:26:52.000000000 +0100
@@ -1673,6 +1673,8 @@ strictopen:
  if (isdir)
  *isdir = TRUE;
  (void) close(openfd); /* don't leak fds */
+ /* Set useful error number.  */
+ errno = EISDIR;
  return NULL;
  }
  }

Andreas.

--
Andreas Schwab, schwab@...
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



Re: WHINY_USERS=0

by tumm :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

so the default (undocumented) behavior is that for(i in a) processes i
in sorted order?

i'm puzzled by that. i remember Kerningham saying they had that in awk
1.0 then pulled it our cause it made everything too slow. aharon- did
you come up with some neat incremental sorting trick?

t

On Mon, Oct 26, 2009 at 5:26 AM, Hermann Peifer <peifer@...> wrote:

> Aharon Robbins wrote:
>>
>> It's what programmer types call an "easter egg", meaning an undocumented
>> feature with unusual or interesting behavior, and I intend to keep it
>> that way (but see the gawk.texi file :-).
>>
>> The feature as coded means "if WHINY_USERS exists in the environment,
>> enable the whiny user related features." (There are at least two.)
>>
>> So, the behavior you're seeing is what I wanted.  I don't intend to
>> change it.
>>
>> Personally, I think you should use asort or asorti if you want array
>> sorting. The code is much clearer that way.
>
> Aharon,
>
> Thanks for the explanations, which confirms my observation that
> WHINY_USERS=0 isn't enough to unset the variable.
>
> About asort() and asorti(): I use these functions occasionally, but what I
> actually need most are simply sorted *original* array indices (which almost
> always have some meaning, like country code, or similar, so I don't want to
> destroy them). IMO, there is nothing better and cleaner than WHINY_USERS to
> achieve this gawk behaviour. The built-in asorti() function forces me to
> copy src array into dest array in order to avoid the loss of original
> indices. This makes the code more complicated, as I see it.
>
> Anyway: I actually didn't want to start a discussion here. Thanks again for
> the WHINY_USERS easter egg!.
>
> Hermann
>
> PS for Tim: You might want to re-visit your WHINY_USERS performance test
> described in http://awk.info/?tip/whinyUsers
>



--
there are those who call me... (dr) timm (menzies)?
morgantown (39.6n, -79w), usa
assoc prof csee, wvu
http://menzies.us

'Hydrogen is a light, odorless gas, which, given enough time, turns
into people.'



Re: WHINY_USERS=0

by John Cowan :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Tim Menzies scripsit:

> so the default (undocumented) behavior is that for(i in a) processes i
> in sorted order?

No, the default behavior is to process in random order.  The undocumented
environment variable WHINY_USERS uses sorted order instead.

--
John Cowan    cowan@...    http://ccil.org/~cowan
Heckler: "Go on, Al, tell 'em all you know.  It won't take long."
Al Smith: "I'll tell 'em all we *both* know.  It won't take any longer."



Re: WHINY_USERS=0

by Dave B-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Monday 26 October 2009, Tim Menzies wrote:

> so the default (undocumented) behavior is that for(i in a) processes i
> in sorted order?

No, the default is unspecified order. If the variable WHINY_USERS exists in
the environment (with any value, including 0) then the indices are returned in
order.

--
D.



Parent Message unknown Re: WHINY_USERS=0

by Aharon Robbins :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for this. You beat me to it.

Arnold

> From schwab@...  Fri Oct 30 13:12:16 2009
> X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on server1.f7.net
> X-Spam-Level:
> X-Spam-Status: No, score=-6.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED
> autolearn=ham version=3.2.4
> X-Envelope-From: schwab@...
> X-Envelope-To: <arnold@...>
> From: Andreas Schwab <schwab@...>
> To: Hermann Peifer <peifer@...>
> Cc: bug-gnu-utils@..., menzies.tim@...,
>         Aharon Robbins <arnold@...>
> Subject: Re: WHINY_USERS=0
> X-Yow: You mean you don't want to watch WRESTLING from ATLANTA?
> Date: Mon, 26 Oct 2009 13:37:21 +0100
> Content-Type: text/plain; charset=us-ascii
> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17
>
> Hermann Peifer <peifer@...> writes:
>
> > $ gawk '1' somedir/ somefile
> > gawk: cmd. line:1: fatal: cannot open file `somedir/' for reading (Success)
>
> 2009-10-26  Andreas Schwab  <schwab@...>
>
> * io.c (iop_open): Set errno when rejecting a directory.
>
> --- io.c.~1.25.~ 2009-10-16 08:50:33.000000000 +0200
> +++ io.c 2009-10-26 13:26:52.000000000 +0100
> @@ -1673,6 +1673,8 @@ strictopen:
>   if (isdir)
>   *isdir = TRUE;
>   (void) close(openfd); /* don't leak fds */
> + /* Set useful error number.  */
> + errno = EISDIR;
>   return NULL;
>   }
>   }
>
> Andreas.
>
> --
> Andreas Schwab, schwab@...
> GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
> "And now for something completely different."
>