bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] Missing double quotes in SYMTAB example in docs


From: david kerns
Subject: Re: [bug-gawk] Missing double quotes in SYMTAB example in docs
Date: Mon, 11 Jul 2016 12:41:55 -0700

So, I wasn't really familiar with the built-in SYMTAB ... this one-liner made it obvious though:

awk 'BEGIN { for (i in SYMTAB) print i }'

Based on that output, (it appears to be the running program's symbol table) I would say: yes, the documentation is misleading, and the index of SYMTAB should resolve to the name of a variable.

 
BEGIN {
        i = 10
        multiply("i", 2)
        print i
}
function multiply(i, amount)
{
    return SYMTAB[i] *= amount
}


On Mon, Jul 11, 2016 at 11:23 AM, Jaromir Obr <address@hidden> wrote:
Based on the example originally I tested this:

BEGIN {
        i = 10
        multiply(i, 2)
        print i
}
function multiply(i, amount)
{
    return SYMTAB[i] *= amount
}
but it didn't work as expected (result is 10 instead 20). Therefore I would expect SYMTAB["i"].

Mira

On Sun, Jul 10, 2016 at 10:25 PM, david kerns <address@hidden> wrote:
if it used less descriptive names, say a and b, would you still say it needs double quotes?

# Indirect multiply of any variable by amount, return result
function multiply(a, b)
{
    return SYMTAB[a] *= b
}

On Sun, Jul 10, 2016 at 10:24 AM, Jaromir Obr <address@hidden> wrote:
Hi,


# Indirect multiply of any variable by amount, return result
function multiply(variable, amount)
{
    return SYMTAB[variable] *= amount
}

There are missing double quotes around variable, aren't they ? (expected is return SYMTAB["variable"] *= amount

Regards

Jaromir




reply via email to

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