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: Tue, 14 May 2019 14:13:59 +0300

After rereading the manual and having some tests, I finally found the answer to 
my first question. There's no trouble.
Two questions are still actual. I'll formulate them here.

1. According to the manual (9.1.7 Getting Type Information):

"unassigned - x is a scalar variable that has not been assigned a value yet."

"And in fact, due to the way gawk works,
if you pass the name of a variable that has not been previously used to 
isarray(),
gawk ends up turning it into a scalar."

But the result of "typeof" function after passing a variable to isarray() is:

$ gawk 'BEGIN { if (! isarray(x)) { print typeof(x) } }'
untyped

Not "unassigned". Why? Is it a bug?

2. The last sentence of the section "9.1.7 Getting Type Information" is:

"The typeof() function is general; it allows you to determine
if a variable or function parameter is a scalar, an array, or a strongly typed 
regexp."

A strongly typed regexp is a sort of scalar, isn't it?
I don't understand why it is mentioned separately in this sentence.

_______________

Yours respectfully,
Mark Krauze

13.05.2019, 23:38, "M" <address@hidden>:
> In addition, concerning the fourth example:
>
> $ gawk 'BEGIN { if (! isarray(x)) { print typeof(x) } }'
> untyped
>
> According to the manual:
>
> "And in fact, due to the way gawk works, if you pass
> the name of a variable that has not been previously used to isarray(), gawk
> ends up turning it into a scalar."
>
> So, I expected to see "unassigned" in the output.
> However, there is "untyped" in the output.
>
> _______________
>
> Yours respectfully,
> Mark Krauze
>
> 13.05.2019, 22:52, "M" <address@hidden>:
>>  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]