[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: typeof() creates elements in an array
From: |
Andrew J. Schorr |
Subject: |
Re: typeof() creates elements in an array |
Date: |
Tue, 28 Sep 2021 08:40:48 -0400 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Mon, Sep 27, 2021 at 08:44:05PM -1000, david kerns wrote:
> Not a bug
>
> Remove the typeof operator and you’ll see the array is still increased.
> Referencing the new element increases the length
>
Agreed.
> > On Sep 27, 2021, at 11:13 AM, Ivo Palli <ivo@palli.nl> wrote:
> >> Normally, passing a variable that has never been used to a built-in
> >> function causes it to become a scalar variable (unassigned). However,
> >> isarray() and typeof() are different; they do not change their arguments
> >> from untyped to unassigned.
Here's what looks like a more interesting question to me regarding
this issue.
bash-4.2$ ./gawk 'BEGIN {print typeof(x); x[0] = 0; print typeof(x)}'
untyped
array
bash-4.2$ ./gawk 'BEGIN {print typeof(x[0]); x[0][0] = 0; print typeof(x[0])}'
unassigned
gawk: cmd. line:1: fatal: attempt to use scalar `x["0"]' as an array
This example does seem to be more at odds with the language in the manual,
since the array element here has been created as a unassigned scalar, not
as an untyped value. I don't know whether that can be avoided. The array
instantiation stuff is tricky.
Regards,
Andy
- typeof() creates elements in an array, Ivo Palli, 2021/09/27
- Re: typeof() creates elements in an array, david kerns, 2021/09/28
- Re: typeof() creates elements in an array,
Andrew J. Schorr <=
- Re: typeof() creates elements in an array, arnold, 2021/09/29
- Re: typeof() creates elements in an array, Andrew J. Schorr, 2021/09/29
- Re: typeof() creates elements in an array, arnold, 2021/09/29
- Re: typeof() creates elements in an array, arnold, 2021/09/30
- Re: typeof() creates elements in an array, Andrew J. Schorr, 2021/09/30
- Re: typeof() creates elements in an array, arnold, 2021/09/30
- Re: typeof() creates elements in an array, Andrew J. Schorr, 2021/09/30
Re: typeof() creates elements in an array, arnold, 2021/09/29