bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] On uninitialized variables


From: M
Subject: Re: [bug-gawk] On uninitialized variables
Date: Mon, 13 May 2019 22:52:03 +0300

Thank you!
And another question about unassigned variables.
When does a variable with a type "untyped" turn into a type "unassigned" (and 
vice versa, if it's even possible)?

With GNU AWK v5.0.0 I have the following:

$ gawk 'BEGIN { print typeof(x) }'
untyped
$ gawk 'BEGIN { print typeof(x); print typeof(x) }'
untyped
untyped
$ gawk 'BEGIN { if (x == "") { print typeof(x) } }'
unassigned
$ gawk 'BEGIN { if (! isarray(x)) { print typeof(x) } }'
untyped
$ gawk 'BEGIN { if (! x) { print typeof(x) } }'
unassigned

In the section "9.1.7 Getting Type Information" for "untyped":

"x has not yet been used yet at all; it can become a scalar or an array."

As far as I understand x is "untyped" because it hasn't yet been used in a 
scalar or array context.
Am I right?

If it is so, there are some functions like "typeof" or "isarray" which don't 
define a context, so to speak.
I don't know how many of them there are.
Thus (theoretically) you can _use_ a variable x, but after such operations it 
still has a type "untyped".

_______________

Yours respectfully,
Mark Krauze

13.05.2019, 22:11, "address@hidden" <address@hidden>:
> Hi.
>
> M <address@hidden> wrote:
>
>>  Hello! When rereading the manual (v5.0.0), I noticed an inexact statement
>>  in Chapter 1:
>>
>>  1.5 A More Complex Example
>>
>>  "(This works because awk variables are automatically initialized to
>>  zero.)"
>>
>>  It's true only in a numeric context.
>>  When used as strings, uninitialized variables are automatically
>>  initialized to an empty string.
>>  Although this peculiarity is emphasised throughout the rest of the manual,
>>  I think it would be useful to mention about it in the introduction
>>  chapter too (especially for novices).
>
> Thanks for the note. Looking at the section as a whole, I think it
> would be distracting to try to introduce information about initialization
> to the empty string. Sometimes it's better not to be fully complete.
>
> So, I appreciate your making the suggestion, but I think it better to
> leave that section alone.
>
> Thanks!
>
> Arnold



reply via email to

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