Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: WHINY_USERS=0

0 views
Skip to first unread message

Aharon Robbins

unread,
Oct 25, 2009, 4:06:54 PM10/25/09
to bug-...@gnu.org, pei...@gmx.eu, menzi...@gmail.com
Greetings. Re this:

> Date: Fri, 23 Oct 2009 19:41:26 +0200
> From: Hermann Peifer <pei...@gmx.eu>
> To: bug-...@gnu.org
> CC: menzi...@gmail.com
> 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


John Cowan

unread,
Oct 25, 2009, 10:55:19 PM10/25/09
to Aharon Robbins, menzi...@gmail.com, pei...@gmx.eu, bug-...@gnu.org
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 co...@ccil.org
he doesn't exist or you don't exist, http://www.ccil.org/~cowan
but you won't know which. --Melvin Fitting


Hermann Peifer

unread,
Oct 26, 2009, 6:26:19 AM10/26/09
to Aharon Robbins, menzi...@gmail.com, bug-...@gnu.org
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


Hermann Peifer

unread,
Oct 26, 2009, 6:47:23 AM10/26/09
to John Cowan, Aharon Robbins, menzi...@gmail.com
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

Andreas Schwab

unread,
Oct 26, 2009, 8:37:21 AM10/26/09
to Hermann Peifer, menzi...@gmail.com, Aharon Robbins, bug-gn...@gnu.org
Hermann Peifer <pei...@gmx.eu> writes:

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

2009-10-26 Andreas Schwab <sch...@linux-m68k.org>

* 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, sch...@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Tim Menzies

unread,
Oct 26, 2009, 10:20:11 AM10/26/09
to Hermann Peifer, Aharon Robbins, bug-...@gnu.org
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 <pei...@gmx.eu> 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.'


John Cowan

unread,
Oct 26, 2009, 3:04:22 PM10/26/09
to Tim Menzies, bug-...@gnu.org
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 co...@ccil.org 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."


Dave B

unread,
Oct 26, 2009, 3:05:39 PM10/26/09
to bug-...@gnu.org
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.


Aharon Robbins

unread,
Oct 30, 2009, 7:27:42 AM10/30/09
to pei...@gmx.eu, sch...@linux-m68k.org, menzi...@gmail.com, arn...@skeeve.com, bug-gn...@gnu.org
Thanks for this. You beat me to it.

Arnold

> From sch...@linux-m68k.org 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: sch...@linux-m68k.org
> X-Envelope-To: <arn...@skeeve.com>
> From: Andreas Schwab <sch...@linux-m68k.org>
> To: Hermann Peifer <pei...@gmx.eu>
> Cc: bug-gn...@gnu.org, menzi...@gmail.com,
> Aharon Robbins <arn...@skeeve.com>
> 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

0 new messages