bug-gawk
[Top][All Lists]
Advanced

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

Re: Printing arrays from the debugger, once again


From: Hermann Peifer
Subject: Re: Printing arrays from the debugger, once again
Date: Sat, 23 Dec 2023 12:55:05 +0100
User-agent: Mozilla Thunderbird

Just to add another example code for the same issue. I was using latest
gawk code from git/gawk-5.3-stable branch, on a MacBook.

Hermann

> cat test3.awk
@include "walkarray"

BEGIN {
        a[0][1] = 1
        a[0][2] = 2

        # Using untyped b[0] as function argument
        print "b[0] =", typeof(b[0])
        the_func(a[0], b[0])

        # Pre-create b[1] as subarray, as done in the old days
        b[1][1] = ""
        delete b[1][1]

        # Using subarray b[1] as function argument
        print "b[1] =", typeof(b[1])
        the_func(a[0], b[1])

        walk_array(b, "b")
}

function the_func(array1, array2) {
        for (i in array1)
                array2[i] = exp(array1[i])
}
>
> gawk -D -f test3.awk
gawk> r
Starting program:
b[0] = untyped
b[1] = array
b[0][1] = 2.71828
b[0][2] = 7.38906
b[1][1] = 2.71828
b[1][2] = 7.38906
Program exited normally with exit value: 0
gawk> p @b
b["(null)"]["1"] = 2.7182818284590451
b["(null)"]["2"] = 7.3890560989306504
b["1"]["1"] = 2.7182818284590451
b["1"]["2"] = 7.3890560989306504
gawk>


On 22/12/2023 14.29, Hermann Peifer wrote:
See below where "walkarray" prints a[0][1], etc. whereas the debugger
prints a["(null)"]["1"].

The debugger prints a[1] as expected. Maybe because array a[1] already
existed before calling split(), my best guess.

Hermann


a) Using latest gawk code from git/gawk-5.3-stable branch, on my
MacBook, Machine Type: aarch64-apple-darwin23.1.0

 > cat test.awk
@include "walkarray"

{
     split($0, a[0])
     a[1][1]
     split($0, a[1])
}

END { walk_array(a, "a") }
 >
 > cat test.dat
1 2 3
 >
 > gawk -D -f test.awk test.dat
gawk> r
Starting program:
a[0][1] = 1
a[0][2] = 2
a[0][3] = 3
a[1][1] = 1
a[1][2] = 2
a[1][3] = 3
Program exited normally with exit value: 0
gawk> p @a
a["(null)"]["1"] = "1"
a["(null)"]["2"] = "2"
a["(null)"]["3"] = "3"
a["1"]["1"] = "1"
a["1"]["2"] = "2"
a["1"]["3"] = "3"
gawk>


b) Using gawk5.3.0 release, installed via Homebrew

(...)
gawk> p @a
(null)["1"] = "1"
(null)["2"] = "2"
(null)["3"] = "3"
1["1"] = "1"
1["2"] = "2"
1["3"] = "3"
gawk>



reply via email to

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