bug-gawk
[Top][All Lists]
Advanced

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

Re: [bug-gawk] GAWK feature suggestions


From: david kerns
Subject: Re: [bug-gawk] GAWK feature suggestions
Date: Wed, 28 Aug 2019 06:56:57 -0700

I've been using awk since ~ 1986 (RIP AT&T Bell Labs) .. but I too love the
gawk extensions...
However, multi-dimensional arrays is NOT one of them. And while you can't
return an array from a function, you can pass one in and re-initialize it.

$ cat md
func mf(a,i) {
  for (i in a) delete a[i];
  a[1,1] = 2;
  a[1,2] = 3;
  a[2,2] = 4;
}
BEGIN {
  b[1] = primer;
  mf(b);
  for (i in b) {
     n = split(i, idx, SUBSEP);
     if (n == 2) {
       printf("1: %d 2: %d -> %d\n", idx[1], idx[2], b[idx[1],idx[2]]);
     } else {
       print "unexpected index", i;
     }
  }
}
$ awk -version
awk version 20070501
$ awk -f md
1: 1 2: 1 -> 2
1: 1 2: 2 -> 3
1: 2 2: 2 -> 4
$ gawk --version | head -2
GNU Awk 4.2.0, API: 2.0
Copyright (C) 1989, 1991-2017 Free Software Foundation.
$ gawk -f md
1: 1 2: 1 -> 2
1: 1 2: 2 -> 3
1: 2 2: 2 -> 4

On Wed, Aug 28, 2019 at 6:29 AM address@hidden <
address@hidden> wrote:

> Hi,
>
> I've been using awk and now gawk on and off for a number of years, since
> the late 1980s to be exact, usually for one-liners or small scripts.
>
> Gawk is a major step up from awk, in particular multi-dimensional arrays
> and the SYMTAB array which I'm using extensively. The new namespace feature
> is a god-send too as I'm working with multiple library files and avoiding
> name clashes was getting quite complex. I'm now working on developing a
> fairly major project (several thousand lines of code so far), and in the
> course of working on this I've come across a few features that I would find
> really useful, which I'd like to suggest for future consideration.
>
> So, in no particular order :
>
> -        Possibility to return an array from a function. This has probably
> already been requested, it would avoid the need for a number of public
> arrays.
>
> -        Nested functions. Not particularly important, but useful to hide
> helper functions from public view
>
> -        Block comments. Probably already suggested.
>
> -        And most useful for me when testing function libraries: ignore
> all rules if a file is called via @include (or maybe a @ignore-rules
> directive, as there may be rare cases where you want to include rules in an
> @include file). This would allow to combine test code and functions in a
> single file.
>
> Thanks to all who've contributed to this project over the years, keep up
> the good work.
>
> Kind regards,
> Chris Newell
>
> Chris Newell
> Application Support Engineer
> BAE Systems Applied Intelligence
> ___________________________________________________________
>
> E: address@hidden
>
> BAE Systems Applied Intelligence | Level 5, Block 4 | Dundrum Town Centre
> | Sandyford Road | Dundrum | Dublin 16 | D16 A4W6 | Ireland
> www.baesystems.com/ai<http://www.baesystems.com/ai>
>
> BAE Systems will collect and process information about you that may be
> subject to data protection laws. For more information about how we use and
> disclose your personal information, how we protect your information, our
> legal basis to use your information, your rights and who you can contact,
> please refer to the relevant sections of our Privacy note at
> www.baesystems.com/en/cybersecurity/privacy <
> http://www.baesystems.com/en/cybersecurity/privacy>
>
> Please consider the environment before printing this email. This message
> should be regarded as confidential. If you have received this email in
> error please notify the sender and destroy it immediately. Statements of
> intent shall only become binding when confirmed in hard copy by an
> authorised signatory. The contents of this email may relate to dealings
> with other companies under the control of BAE Systems PLC, details of which
> can be found at http://www.baesystems.com/Businesses/index.htm.
>


reply via email to

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