bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] Postdecrementing $NF


From: Manuel Collado
Subject: Re: [bug-gawk] Postdecrementing $NF
Date: Mon, 09 Sep 2013 22:43:42 +0200
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/17.0 Thunderbird/17.0

El 09/09/2013 21:23, Aharon Robbins escribió:

Date: Sun, 08 Sep 2013 20:20:28 +0200
From: Manuel Collado <address@hidden>
To: address@hidden
Subject: Re: [bug-gawk] Postdecrementing $NF

[............]

The real undefined behavior issue is if decrementing NF should in fact drop
the last field, I.e., if decrementing the read-only NF variable should
affect the access to the original fields, or just modify a local user
visible copy of NF.

Not sure what you're trying to say here. NF is not read only; there
are defined semantics for setting it (increasing it or decreasing it).
I am 99% certain that if I looked I could find chapter and verse on this
in the original awk book and probably in POSIX.

I don't know what you mean by "local user visible copy of NF" --- awk
doesn't have scoping a la perl's "my { ... }" construct. (If that's
what you meant. :-)

Ooops! The usage of "local" in this context is incorrect. Please read it as "user visible copy of the internal NF variable".

Sorry for the confusion. My point is that some awk predefined variables are just automatically set by the awk processor at specific times, so they are mostly used as if they were read-only. If the user changes their values the program behavior can became non intuitive.

Please consider, for instance, the FILENAME variable. Its value can be changed by the user, but this doesn't let the program to suddenly start reading input records from the new named file. The current file continues to be read, even if FILENAME retains the user assigned value until a possible new input file is opened.

Of course, the semantics of NF is different from the FILENAME's one. My comment was a general thought about program sanity policy.

With respect to NF, it seems that some (non Posix) awk processors handle it like FILENAME. I.e., changing the value of NF doesn't modify the internal structure that holds the current record. At least this is what I assume after your comment about discrepancies in the evaluation of $(NF--) by different processors.

Regards.
--
Manuel Collado - http://lml.ls.fi.upm.es/~mcollado




reply via email to

[Prev in Thread] Current Thread [Next in Thread]