bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] SYMTAB contains future variables


From: Aharon Robbins
Subject: Re: [bug-gawk] SYMTAB contains future variables
Date: Sun, 12 Oct 2014 12:40:01 +0300
User-agent: Heirloom mailx 12.5 6/20/10

Greetings. Apologies for the delay in replying, I've been under
some deadlines that are now past.

> Date: Sun, 21 Sep 2014 23:17:44 +0200
> From: Joep van Delft <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] SYMTAB contains future variables
>
> Hello, 
>
> Please consider the following program: 
>
>     % gawk 'BEGIN{for(s in SYMTAB){print s};a=1}'
>
> I would expect 'a' not to be in the output, as it is at the time of
> the for loop, a defined global variable or array. Yet it is.
> Neither inserting a sleep call with the system function between the
> for-loop and the assignment, nor moving the assignment to an
> END{}-block, changes the behavior. 

SYMTAB makes gawk's symbol table visible to the awk programmer.  It is
built as gawk parses the program and is complete before the program
starts to run.  By the time gawk has parsed the program, it knows that
a variable named 'a' is used during the program at some point, and this
is why you see 'a' listed in the output.

> What _does_ work, is the following trick to hide the variable name
> to the interpreter: 
>
>     % gawk 'BEGIN{for(s in SYMTAB){print s};SYMTAB["a"]=1}'

You've also removed 'a' as a variable from the program.

It is fully documented that you can add additional elements to SYMTAB;
in your case you've just created an element named "a" with value 1 that
is no different from any other element of any other associative array.

(Being able to add additional elements to SYMTAB may be a minor
mis-feature, but I don't really like the idea of making SYMTAB completely
read-only.)

Hope this helps,

Arnold



reply via email to

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