• Array indices are small integers? (Was: printing words without newlines?)

    From gazelle@gazelle@shell.xmission.com (Kenny McCormack) to alt.comp.lang.awk,comp.lang.awk on Tue May 14 13:40:21 2024
    From Newsgroup: comp.lang.awk

    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).
    --- Synchronet 3.20a-Linux NewsLink 1.114