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: Andrew J. Schorr
Subject: Re: [bug-gawk] Missing double quotes in SYMTAB example in docs
Date: Mon, 11 Jul 2016 17:16:51 -0400
User-agent: Mutt/1.5.23 (2014-03-12)

Hi,

I guess one might consider changing the example in the docs from:

          function multiply(variable, amount)
          {
              return SYMTAB[variable] *= amount
          }

to

          function multiply(variable_name, amount)
          {
              return SYMTAB[variable_name] *= amount
          }

Or maybe we should show expand the example to show a full program:

bash-4.2$ cat /tmp/test.awk 
function multiply(variable_name, amount)
{
    return SYMTAB[variable_name] *= amount
}

BEGIN {
    i = "5"
    multiply("i", 2)
    print i
}
bash-4.2$ gawk -f /tmp/test.awk 
10

Regards,
Andy

On Mon, Jul 11, 2016 at 01:39:30PM -0600, address@hidden wrote:
> Hi.
> 
> What you want is
> 
>       multiply("i", 2)
> 
> Note that the `i' in the multiply function is different from the
> global `i' assigned to in the BEGIN rule.
> 
> HTH,
> 
> Arnold
> 
> 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,
> > >>
> > >> in
> > >> https://www.gnu.org/software/gawk/manual/gawk.html#index-differences-in-awk-and-gawk_002c-SYMTAB-variable
> > >> there is an example:
> > >>
> > >> # 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
> > >>
> > >
> > >
> 

-- 
Andrew Schorr                      e-mail: address@hidden
Telemetry Investments, L.L.C.      phone:  917-305-1748
545 Fifth Ave, Suite 1108          fax:    212-425-5550
New York, NY 10017-3630



reply via email to

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