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: address@hidden
Subject: Re: [bug-gawk] GAWK feature suggestions
Date: Wed, 28 Aug 2019 14:34:29 +0000

Hi David,

Thanks for your reply. I started using awk with an SCO Xenix setup in 1988. 
We’re neither of us getting any younger ☺

By “multi-dimensional array”, I meant the gawk extension, using the 
array[i][j], notation, without the need for SUBSEP. This makes managing 
multi-dimensional arrays easier, but my main point was to have the ability to 
return arrays from a function. For me, in general this seems cleaner and more 
intuitive.

This is of course a personal preference, but in my opinion the array isn’t a 
parameter, it’s the result, so it shouldn’t have to be included in the 
parameters passed into the function.

As a simple example, let’s suppose I want to write a function that returns the 
quotient and remainder for Euclidean division :

This
function euclid(n, d,       ret) {
    ret[“q”] = int(n, d)
    ret[“r”] = n % d
    return ret
}
and
arr = euclid(1023, 17)

seems better than
function euclid(n, d, ret) {
    ret[“q”] = int(n, d)
    ret[“r”] = n % d
}
and
euclid(1023, 17, arr)


Any thoughts on my other suggestions ?

Kind regards,
Chris



From: david kerns [mailto:address@hidden]
Sent: 28 August 2019 14:57
To: Newell, Christopher (IE Dundrum)
Cc: address@hidden; address@hidden
Subject: Re: [bug-gawk] GAWK feature suggestions


PHISHING ALERT
This email has been sent from an account outside of the BAE Systems network.

Be aware that this could be a phishing attempt. For more guidance, search 
"phishing email" on Connect. If you think this is a phishing email report it 
using the "PhishMe" button on Outlook.


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<mailto:address@hidden> 
<address@hidden<mailto: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<mailto: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><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>
 <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.
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]