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: Joep van Delft
Subject: Re: [bug-gawk] SYMTAB contains future variables
Date: Sun, 12 Oct 2014 16:59:29 +0200

Thanks, Arnold! 

On Sun, 12 Oct 2014 12:40:01 +0300
Aharon Robbins <address@hidden> wrote:

> 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
> >
> >     % 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. 
> 
> 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.  

Clear. I think those are exactly the sentences that are missing from
the documentation. It currently reads: 

    SYMTAB #

    An array whose indices are the names of all currently defined
    global variables and arrays in the program. (...)

I interpreted "currently defined" as being related to the runtime.  

> 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.)

No! The variable indirection that writeable SYMTAB provides has
already saved some programming efforts to be in need of a rewrite in
another language. 

> Hope this helps,
> 
> Arnold

It sure does. Thank you! 

Joep






reply via email to

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