[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-gawk] Another typeof() issue
From: |
Aharon Robbins |
Subject: |
Re: [bug-gawk] Another typeof() issue |
Date: |
Mon, 22 Jun 2015 23:07:09 +0300 |
User-agent: |
Heirloom mailx 12.5 6/20/10 |
Hi.
> IIRC, another simple AWK truth is that any reference to a non-existing
> array element creates this element as a scalar. So I am wondering if in
> the below example typeof(a[1]) is really: untyped ?
>
> Hermann
>
> $ awk 'BEGIN{ print typeof(a[1]); a[1][2]}'
> untyped
> awk: cmd. line:1: fatal: attempt to use scalar `a["1"]' as an array
It is and it isn't. a[1] never received a value, but it's not an
array. It's not any different than doing something like
BEGIN {
a[2]
}
a[2] is both the null string and zero; internally it's untyped since
it never received a value. I agree, it's not untyped in the sense
that it can become an array.
Does this look better?
$ cat bar.awk
BEGIN {
print typeof(x)
print typeof(a[1])
a[1][2]
}
$ ./gawk -f bar.awk
untyped
scalar_u
gawk: bar.awk:4: fatal: attempt to use scalar `a["1"]' as an array
This distinguishes between "never used" and "scalar but no value" (scalar_u).
In the meantime I have pushed a bunch of fixes from the other bug
reports.
I'm going to let this change (untyped vs. scalar_u) sit for a bit before
pushing it.
Thanks,
Arnold
- [bug-gawk] Another typeof() issue, Hermann Peifer, 2015/06/22
- Re: [bug-gawk] Another typeof() issue,
Aharon Robbins <=
- Re: [bug-gawk] Another typeof() issue, Hermann Peifer, 2015/06/22
- Re: [bug-gawk] Another typeof() issue, Hermann Peifer, 2015/06/23
- Re: [bug-gawk] Another typeof() issue, Aharon Robbins, 2015/06/26
- Re: [bug-gawk] Another typeof() issue, Hermann Peifer, 2015/06/28
- Re: [bug-gawk] Another typeof() issue, arnold, 2015/06/29
- Re: [bug-gawk] Another typeof() issue, Hermann Peifer, 2015/06/29
- Re: [bug-gawk] Another typeof() issue, Aharon Robbins, 2015/06/29
- Re: [bug-gawk] Another typeof() issue, Hermann Peifer, 2015/06/29
- Re: [bug-gawk] Another typeof() issue, Andrew J. Schorr, 2015/06/29
- Re: [bug-gawk] Another typeof() issue, Aharon Robbins, 2015/06/29