bug-gawk
[Top][All Lists]
Advanced

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

Re: delete of nested array is in consistent


From: david kerns
Subject: Re: delete of nested array is in consistent
Date: Sun, 26 Apr 2020 08:59:40 -0700

you're misunderstanding the language. one of the characteristics of awk is
you don't need to declare variables before using them. you're also parsing
the statement 'delete a[""]' in your head incorrectly. the array element
a[""] is first instantiated (if it doesn't exist already) and then passed
to the routine that deletes it.

On Sun, Apr 26, 2020 at 8:16 AM Peng Yu <address@hidden> wrote:

> I think the main problem is that "delete" should not be used for
> initialisation an array. Once you try to mix up two things into one
> keyword, it becomes confusing.
>
> If there were a keyword like `inita`, it becomes clearer what it
> means. Hence, the awk implementation should be cleaner as well because
> it will not have a conflict with the existing "delete" implementation.
>
> inita a[""]
> inita a[""][""]
> inita a[""][""][""]
>
> On 4/19/20, address@hidden <address@hidden> wrote:
> > You are, of course, welcome to your opinion.  But simply stating
> > it on the bug list is not actually going to effect any changes.
> >
> > Here is an incomplete list of possible things you might do to change
> > things:
> >
> > A. Switch from gawk to Python for all your programming. This is
> > recommended.
> >
> > B. Failing (A), learn C, read the gawk code, and develop a patch to
> > submit for review.
> >
> > C. Failing (B), find someone else to do that for you.
> >
> > D. Failing (C), talk to me offline about my consulting rates.
> >
> > Arnold
> >
> > Peng Yu <address@hidden> wrote:
> >
> >> I feel if `delete a[“”]` can initialize the array, it should be
> intuitive
> >> to support `delete a[1][“”]` as well. The definition of the language
> >> should
> >> be separated from the difficulties in the implementation.
> >>
> >> On Fri, Apr 17, 2020 at 8:46 AM <address@hidden> wrote:
> >>
> >> > I poked at this in a debugger. Basically for
> >> >
> >> >         BEGIN { delete a[1][""]; print typeof(a[1]) }
> >> >
> >> > a[1] never existed as a defined array, just as a[1][""] doesn't have
> >> > any
> >> > value associated with it.  Thus the delete effectively does nothing.
> >> >
> >> > So, when typeof() is called on a[1], it reports undefined, since no
> >> > direct
> >> > assignment was ever made to it.
> >> >
> >> > Andy's suggestion:
> >> >
> >> >         BEGIN { a[1][""]; delete a[1][""]; print typeof(a[1]) }
> >> >
> >> > is the right way to go to force gawk to create a[1] and make it
> >> > into an array.
> >> >
> >> > Forcing that creation from within the delete statement is way too
> >> > hard to do, and definitely much less clear at the awk level as to
> >> > what's going on anyway.
> >> >
> >> > Arnold
> >> >
> >> > "Andrew J. Schorr" <address@hidden> wrote:
> >> >
> >> > > On Fri, Apr 17, 2020 at 01:26:17AM -0600, address@hidden wrote:
> >> > > > Peng Yu <address@hidden> wrote:
> >> > > >
> >> > > > > See below. I'd expect the second one should also print array. Is
> >> > > > > it
> >> > a bug?
> >> > > > >
> >> > > > > $ awk -e 'BEGIN { delete a[""]; print typeof(a) }'
> >> > > > > array
> >> > > > > $ awk -e 'BEGIN { delete a[1][""]; print typeof(a[1]) }'
> >> > > > > unassigned
> >> > > > >
> >> > > > > --
> >> > > > > Regards,
> >> > > > > Peng
> >> > > >
> >> > > > Upgrade your version of gawk:
> >> > > >
> >> > > > $ ./gawk --version | sed 2q
> >> > > > GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.0.1, GNU MP 6.1.2)
> >> > > > Copyright (C) 1989, 1991-2020 Free Software Foundation.
> >> > > > $ ./gawk 'BEGIN { delete a[""]; print typeof(a) }'
> >> > > > array
> >> > > > $ ./gawk 'BEGIN { delete a[1][""]; print typeof(a) }'
> >> > > > array
> >> > >
> >> > > Actually, in latest gawk, his second example still says unassigned:
> >> > >
> >> > > bash-4.2$ ./gawk --version | head -1
> >> > > GNU Awk 5.1.0, API: 3.0 (GNU MPFR 3.1.1, GNU MP 6.0.0)
> >> > > bash-4.2$ ./gawk 'BEGIN { delete a[1][""]; print typeof(a[1]) }'
> >> > > unassigned
> >> > >
> >> > > This gives the desired outcome:
> >> > > bash-4.2$ ./gawk 'BEGIN { a[1][""]; delete a[1][""]; print
> >> > > typeof(a[1])
> >> > }'
> >> > > array
> >> > >
> >> > > Regards,
> >> > > Andy
> >> >
> >> > --
> >> Regards,
> >> Peng
> >
>
>
> --
> Regards,
> Peng
>
>


reply via email to

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