Deutsch   English   Français   Italiano  
<v1vpk5$vbji$1@news.xmission.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: alt.comp.lang.awk,comp.lang.awk
Subject: Array indices are small integers? (Was: printing words without newlines?)
Date: Tue, 14 May 2024 13:40:21 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <v1vpk5$vbji$1@news.xmission.com>
References: <v1pi7c$2b87j$1@dont-email.me> <20240513100418.652@kylheku.com> <v1tih0$u8kt$1@news.xmission.com> <20240513162301.128@kylheku.com>
Injection-Date: Tue, 14 May 2024 13:40:21 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
	logging-data="1027698"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
Bytes: 2645
Lines: 40

In article <20240513162301.128@kylheku.com>,
Kaz Kylheku  <643-408-1753@kylheku.com> wrote:
....
>> Final note: In fact, it has been established (on this newsgroup as well as
>> empirically by me and others) that if the indices are small integers, you
>> get sorting for free (in GAWK, which, as noted, is all we care about).  So,
>> you don't even really need to mess with PROCINFO[]...
>
>Are you referring to the idea of just replacing the above for + if
>structure with:
>
>  for (i in rank) {
>
>  }
>
>and relying on the small integer indices being hashed in order?

Yes.

>Where is that documented? The manual reiterates that this is not
>specified: "By default, the order in which a for (indx in array) loop
>scans an array is not defined; it is generally based upon the internal
>implementation of arrays inside awk."

It is documented in this newsgroup (Google is your friend).
And assented to by one or both of the GAWK insiders who are known to post here.
It seems to be an attribute (i.e., quirk) of the particular hashing
algorithm used.

Now, of course it isn't guaranteed and could disappear in some future
version of GAWK - and, of course, one wouldn't rely on it in production
code, since it is so easy to make it right by including the line (shown in
this thread's OP) that sets PROCINFO[].

But it is true, nonetheless.

-- 
The key difference between faith and science is that in science, evidence that
doesn't fit the theory tends to weaken the theory (that is, make it less likely to
be believed), whereas in faith, contrary evidence just makes faith stronger (on
the assumption that Satan is testing you - trying to make you abandon your faith).