bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] isarray() is assigning a type to its argument


From: Ed Morton
Subject: Re: [bug-gawk] isarray() is assigning a type to its argument
Date: Sat, 13 May 2017 08:37:18 -0500
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

Thanks, make sense and thanks for the correct way to write my code.

On 5/13/2017 8:26 AM, Wolfgang Laun wrote:
It's not the isarray that is to blame, it is referencing a[1] that creates a[1], necessarily as a scalar. It's a variant of the hen-egg problem.

The more cumbersome isarray(1 in a ? a[1] : 0) avoids this.

-W



On 13 May 2017 at 14:47, Ed Morton <address@hidden> wrote:
wrt this code:

awk 'BEGIN {
    a[1][2] = 7
    print "value:", a[1][2]
}'
value: 7

I did not expect that testing whether or not a[1] was an array first would force a[1] to be a scalar thereafter:

awk 'BEGIN {
    print "isarray:", isarray(a[1])
    a[1][2] = 7
    print "value:", a[1][2]
}'
isarray: 0
awk: cmd. line:3: fatal: attempt to use scalar `a["1"]' as an array

To me that's like if the "in" operator in an "if" condition caused the value to be present in an array, i just want to test for something, not affect it. Is that a bug or a design decision?

$ gawk --version | head -2
GNU Awk 4.1.4, API: 1.1 (GNU MPFR 3.1.5, GNU MP 6.1.2)
Copyright (C) 1989, 1991-2016 Free Software Foundation.

$ bash --version | head -2
GNU bash, version 4.4.12(3)-release (x86_64-unknown-cygwin)
Copyright (C) 2016 Free Software Foundation, Inc.

Regards,

    Ed.




reply via email to

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