On 2016-06-08, Andrew Schorr <
asc...@telemetry-investments.com> wrote:
> On Tuesday, June 7, 2016 at 4:43:52 PM UTC-4, Kaz Kylheku wrote:
>> It is glaring hypocrisy to engage in Gawk-specific discussion, yet
>> insist that Tawk is off-topic.
>
> Ha. You got me -- I am undoubtedly a complete and utter hypocrite. :-)
>
> I should not have said that TAWK is off-topic. However, I still don't
> think it's a great thing that TAWK implements array subscripts in a
> way that conflicts with the standard and with how other awk
> implementations behave.
Though it conflicts in some ways, you can write code that will work
the same way, e.g. array["0001234"+0] = 42; print array[1234].
That is to say, we can abstract away a common dialect (let's call it
"Portable Awk" in which it is "implementation-defined" whether integer
array subscripts are treated as integer keys from strings, or whether
they are always reduced to decimal strings which are then used as keys.
In the more rigidly defined "POSIX Awk" this matter is not
implementation-defined; the keying is required to be string-based.
You can write in "Portable Awk" by avoiding a dependence on that
"implementation-defined" choice, and only use arithmetically
normalized values as array indices: never a string with extra
spaces, leading zeros or a gratuitious plus sign.
Are portability issues even a big deal? Does anyone have 250,000 lines
of Awk to port from one Awk to another?
Lastly, is it even good idea to ever write code in any Awk dialect whose
correctness depends on "001234" and 1234 being distinct indices?
> FYI, internally, gawk does have optimizations
> for integer subscripts, so there is a performance benefit in the
> common case of using integer indices. But the subscript values should
> always behave as if they were strings. I'm in the midst of trying to
> fix a few bugs related to this aspect, so it's a topic of some concern
> at the moment.
Bugs, you say? Would these bugs affect "Portable Awk" programs or just
those foolishly optimistic ones written in POSIX Awk? ;)