Gawk bug, gawk won't nawk. 
Author Message
 Gawk bug, gawk won't nawk.

gawk: cmd. line:40: fatal: function `ports': can't use function name
as parameter name

function port_count(wires, PA){ return split((ports(wires)), PA) }

This works on nawk!



Sat, 25 Dec 2004 12:47:33 GMT  
 Gawk bug, gawk won't nawk.

Quote:

>gawk: cmd. line:40: fatal: function `ports': can't use function name
>as parameter name

Useful to mention which gawk version you're using, as well as OS and OS
version.

Quote:
>function port_count(wires, PA){ return split((ports(wires)), PA) }

>This works on nawk!

And the following works on WinNT4SP5 under gawk 3.1.0 with and without --posix.

BEGIN {
  print port_count("abc", a)
  for (i in a) print i, a[i]

Quote:
}

function port_count(wires, PA) { return split((ports(wires)), PA) }

function ports(s) { gsub(/./, "& ", s); sub(/ $/, "", s); return s }

This seems to be more likely a bug in your script code than in gawk. Care to
post more of your script?



Sat, 25 Dec 2004 13:31:56 GMT  
 Gawk bug, gawk won't nawk.

Quote:
> gawk: cmd. line:40: fatal: function `ports': can't use function name
> as parameter name

> function port_count(wires, PA){ return split((ports(wires)), PA) }

> This works on nawk!

This is not a very good bug report, but I tried some testing on my gawk
3.0.4 under Win98.

I made some assumptions, since you didn't post enough code--specifically,
the function ports()--and you didn't document whether "wires" is an array or
a scalar.

First, 'ports(wires)' is indeed a function call.  Thus, it must return a
scalar.  The expression '(ports(wires))' has unnecessary parenthesis, but is
a valid scalar expression.

Further, you are split()ing the retun value of ports(), so it must be some
sort of string, in which you are expecting to see whitespace (the deault
sepatator).

From this, I wrote a dummy ports() function.

As noted above, you don't say whether 'wires' is supposed to be a scalar or
an array.  So I called port_count() (and thus, ports()) with both.

'PA', I assume, is a gobal variable--since it isn't in port_count()'s
parameter list.  And since you are split()ing into it, you must want it to
be an array when you are done with it.

Given all of that, I see no bug.  If you still see a problem, do the
responsible bug-reporting thing, and write a short, complete, program that
works in nawk, and won't compile in gawk, document what it is supposed to
do, and post the command lines and the output..

     - Dan

funcbug.awk
----------
    function ports(w) { return "Hi there" }
    function port_count(wires, PA){ return split( (ports(wires)), PA ) }
    BEGIN {
        x = ""
        print "port_count(x, PA): " port_count(x, PA)
        for (i in PA) print "PA[" i "]: " PA[i]
        delete PA
        xArr[0] = ""
        print "port_count(xArr, PA): " port_count(xArr, PA)
        for (i in PA) print "PA[" i "]: " PA[i]
    }

(output)
----------
    >awk -f funcbug.awk
    port_count(x, PA): 2
    PA[1]: Hi
    PA[2]: there
    port_count(xArr, PA): 2
    PA[1]: Hi
    PA[2]: there



Sat, 25 Dec 2004 13:45:38 GMT  
 Gawk bug, gawk won't nawk.

Quote:


> > gawk: cmd. line:40: fatal: function `ports': can't use function name
> > as parameter name

> > function port_count(wires, PA){ return split((ports(wires)), PA) }

> > This works on nawk!

> This is not a very good bug report, but I tried some testing on my gawk
> 3.0.4 under Win98.

> I made some assumptions, since you didn't post enough code--specifically,
> the function ports()--and you didn't document whether "wires" is an array
or
> a scalar.

> First, 'ports(wires)' is indeed a function call.  Thus, it must return a
> scalar.  The expression '(ports(wires))' has unnecessary parenthesis, but
is
> a valid scalar expression.

> Further, you are split()ing the retun value of ports(), so it must be some
> sort of string, in which you are expecting to see whitespace (the deault
> sepatator).

> From this, I wrote a dummy ports() function.

> As noted above, you don't say whether 'wires' is supposed to be a scalar
or
> an array.  So I called port_count() (and thus, ports()) with both.

> 'PA', I assume, is a gobal variable--since it isn't in port_count()'s
> parameter list.  And since you are split()ing into it, you must want it to
> be an array when you are done with it.

> Given all of that, I see no bug.  If you still see a problem, do the
> responsible bug-reporting thing, and write a short, complete, program that
> works in nawk, and won't compile in gawk, document what it is supposed to
> do, and post the command lines and the output..

>      - Dan

> funcbug.awk
> ----------
>     function ports(w) { return "Hi there" }
>     function port_count(wires, PA){ return split( (ports(wires)), PA ) }
>     BEGIN {
>         x = ""
>         print "port_count(x, PA): " port_count(x, PA)
>         for (i in PA) print "PA[" i "]: " PA[i]
>         delete PA
>         xArr[0] = ""
>         print "port_count(xArr, PA): " port_count(xArr, PA)
>         for (i in PA) print "PA[" i "]: " PA[i]
>     }

> (output)
> ----------
>     >awk -f funcbug.awk
>     port_count(x, PA): 2
>     PA[1]: Hi
>     PA[2]: there
>     port_count(xArr, PA): 2
>     PA[1]: Hi
>     PA[2]: there

One more test, acting on the error message you got:

    ...can't use function name as parameter name

I figured, maybe, you aren't allowed to use an identifier as an element in a
parameter list, when you have used the same identifier as a function name
elsewhere.  So, I revised the code to:

    function ports(w) { return "Hi there" }
    function port_count(wires, PA){ return split( (ports(wires)), PA ) }
    function karl(ports) { return 1 }
    BEGIN {
        x = ""
        print "port_count(x, PA): " port_count(x, PA)
        for (i in PA) print "PA[" i "]: " PA[i]
        print karl(x)
        delete PA
        xArr[0] = ""
        print "port_count(xArr, PA): " port_count(xArr, PA)
        for (i in PA) print "PA[" i "]: " PA[i]
        print karl(xArr)
    }

and it still works.

Finally, I tried adding this bit of nastiness, and killed my gawk (well
Norton said it would have died, anyway.)

    function argh(argh) { return "argh:" argh }
    :
    print argh("argh")

Interestingly enough, it did compile without error...it was when the line
executed that bad things happened.  I added a print,

    function argh(argh) { printf "."; return "argh:" argh }

and only got one "." before it died, so it was not recursing.  Removing the
reference to the parameter 'argh' was enough to make it work:

    function argh(argh) { printf "."; return "argh:" }

So, maybe Mr. Robbins, or others that know, can say whether the definition
'function argh(argh){}' is legal.

    - Dan



Sat, 25 Dec 2004 14:11:39 GMT  
 Gawk bug, gawk won't nawk.

Quote:
> gawk: cmd. line:40: fatal: function `ports': can't use function name
> as parameter name

> function port_count(wires, PA){ return split((ports(wires)), PA) }

> This works on nawk!

Further to Harlan and Dan's responses:

Depending upon the system that you are using, which you ought to
mention, nawk isn't always POSIX compliant, whereas gawk is.  You could
try using gawk --traditional to invoke your script, but I suspect that
it is the extra parentheses around ports(wires) that may be causing your
problem, try removing them.

It would also help if you tell us the gawk version.

HTH
--
Peter S Tillier
"Who needs perl when you can write dc and sokoban in sed?"
peter{dot}tillier<at>btinternet[dot]com
To reply direct to me please use the above address
not the "Reply To" which activates a spam trap.



Sat, 25 Dec 2004 14:07:13 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. awk, nawk & gawk

2. large nawk program migrating to gawk

3. RS problem in nawk (it works with gawk and mawk)

4. AWK/NAWK/GAWK questions !

5. How is this done in awk/nawk/gawk?

6. nawk -> gawk/mawk

7. Differences between awk/nawk/gawk/mawk

8. RE different in NAWK and GAWK?

9. Performance gawk v nawk

10. Gawk for win32 slower than Gawk for Dos_32?

11. gawk 3.0.95, beta for gawk 3.1.0, now available

12. GAWK with 'tail -f'

 

 
Powered by phpBB® Forum Software