help-gawk
[Top][All Lists]
Advanced

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

Re: Hi there, a question about typeof()


From: david kerns
Subject: Re: Hi there, a question about typeof()
Date: Mon, 27 Sep 2021 07:44:55 +1000

if you add two more print statements to check the length of b, you see
exactly what happens...

BEGIN {

split("123", b, "");  # Split a line


print length(b);      # 3 - as it should


print typeof(b[0]);   # unassigned

*print length(b);   *   # 4 (because you created b[0])

print typeof(b[1]);   # strnum

print typeof(b[2]);   # strnum

print typeof(b[3]);   # strnum

*print length(b);   *   # still hanging at 4... but we're about to create a
5th ...

print typeof(b[4]);   # unassigned


print length(b);      # 5 - euhm, what?


# Like quantum physics, observing changes the observed


exit

}




On Mon, Sep 27, 2021 at 6:59 AM Ivo Palli <gawk@ivo.palli.nl> wrote:

> Hiya..
>
> I ran into this:
>
> BEGIN {
> split("123", b, "");  # Split a line
>
> print length(b);      # 3 - as it should
>
> print typeof(b[0]);   # unassigned
> print typeof(b[1]);   # strnum
> print typeof(b[2]);   # strnum
> print typeof(b[3]);   # strnum
> print typeof(b[4]);   # unassigned
>
> print length(b);      # 5 - euhm, what?
>
> # Like quantum physics, observing changes the observed
>
> exit
> }
>
>
> This is a little unexpected since
>
> https://www.gnu.org/software/gawk/manual/html_node/Type-Functions.html
>
> says:
>
> 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.
>
>
> Is the manual just vague or is this unwanted behavior (as I personally
> think it is)?
>
> Regards,
>
>    Ivo Palli
>
>


reply via email to

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