bug-gawk
[Top][All Lists]
Advanced

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

Re: typeof() creates elements in an array


From: arnold
Subject: Re: typeof() creates elements in an array
Date: Sat, 02 Oct 2021 12:58:16 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Thanks for your note. We're aware of the pitfalls. As I said, the jury
is still out; it's not definite that anything is going to change.

Arnold

Tom Gray <tom_gray@keysight.com> wrote:

> If you do that the manual will break again and require even more fine print.
> "A reference to an array element that does not exist automatically creates 
> that array element"
>
> Also changing the behavior could break existing code.
>
> What would be a more helpful enhancement is a more succinct way to declare 
> and array without assigning any elements.
>
> Now we must do something like this to declare x[0] is an array:
>
>    x[0][""]
>    delete x[0][""]
>
> This might be better:
>
>    x[0][]
>
> But it's a syntax error. If it were not a syntax error, what would it return? 
> .... a pointer to an array? Now we'd have something useful.
>
>    y = x[0][]
>    y[1] = "foo"
>    print x[0][1]
>
> Although, I have to admit that I've gotten really good at recursion when I 
> have to search arrays and do work on sub arrays.
>
> Tom
>
> -----Original Message-----
> From: bug-gawk <bug-gawk-bounces+tom_gray=keysight.com@gnu.org> On Behalf Of 
> arnold@skeeve.com
> Sent: Friday, October 01, 2021 1:42 AM
> To: aschorr@telemetry-investments.com; arnold@skeeve.com
> Cc: ivo@palli.nl; bug-gawk@gnu.org
> Subject: Re: typeof() creates elements in an array
>
> CAUTION: This message originates from an external sender.
>
> "Andrew J. Schorr" <aschorr@telemetry-investments.com> wrote:
>
> > > Which language in the manual, please?
> >
> > I was referring to the language he originally cited:
> >
> > "   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."
>
> I have added some additional language to the manual that should clarify 
> things some.
>
> Andy and I are currently exploring if something like
>
>         BEGIN {
>                 print typeof(x[0])
>                 x[0][1] = "foo"
>                 print x[0][1]
>         }
>
> can be made to work "reasonably".  The jury is still out.
>
> Thanks,
>
> Arnold
>



reply via email to

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