Non-standard AWK

3 views
Skip to first unread message

Lorance Stinson

unread,
Apr 4, 2010, 8:43:54 AM4/4/10
to awkcookbook
I've been taking peeks here and there are some of the code and have
noticed a few bit of non-standard AWK. For example using delete to
delete the contents of an array. That is a GAWK extension that appears
to have been carried over to MAWK. This would fail in GAWK with the "--
posix" option, which is how I tend to test my code. If we are going to
use these extensions then they should be pointed out, even if the
standard alternative is not included.

Tim Menzies

unread,
Apr 4, 2010, 9:00:20 AM4/4/10
to awkco...@googlegroups.com
since we are running a test suite as well as source code, we have to
commit to an execution engine. me, i'm happy with gawk 3.1.7 and
would move that to 3.1.8 once that becomes widely available (i WANT
indirect functions so badly- they would simplify my state machine and
OO code sooooo much).

now, in this case, your review could recommend that Arrays contains a
menu item "How to Delete the Entire Contents of an Array" and that has
a function "zap" that....

function zap(a) {
#for(i in a) delete a[i] # uncomment for awks other than gawk
delete a
}

enjoy!
:-)

t

> --
> To unsubscribe, reply using "remove me" as the subject.
>

--
there are those who call me... tim (menzies, ph.d.)
morgantown (39.6n, -79w), usa
assoc prof csee, wvu
http://menzies.us
1-304-376-2859

PROBLEM: Handling e-mail is very very very slow, resulting in inbox overflow.
SOLUTION: Adopt the "http://four.sentenc.es" policy: no responses
longer than 4 sentences. It’s that simple. Care to try it?

Lorance Stinson

unread,
Apr 4, 2010, 9:10:31 AM4/4/10
to awkco...@googlegroups.com
That function is exactly what I was thinking as I have seen it before
on this exact topic.

For now I will point out where something uses non-standard AWK and we
can worry about it later. Perhaps an appendix or online reference for
antique AWKs. It is becoming less of an issue all the time since most
people use the newer AWKs. Darn kids, get off my lawn!! ;-)

--
http://lorance.freeshell.org/
(678) 683-9149

Michael Richter

unread,
Apr 4, 2010, 11:15:12 AM4/4/10
to awkco...@googlegroups.com
On my machine I have:
  • gawk 3.1.6
  • mawk 1.3.3
  • jawk 1.02
  • awk (version uncertain)
The first two I did not install -- they were just there by default on my Ubuntu system.  Plain old original awk I installed out of curiosity and jawk I installed to ensure I have a decent awk implementation on my USB stick that I could run anywhere.

I think that a cookbook for awk should probably give coverage in some form to the language family, not one particular dialect.  We should pick one (gawk, most likely, seeing as it's the most omnipresent) as
--
"Perhaps people don't believe this, but throughout all of the discussions of entering China our focus has really been what's best for the Chinese people. It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.

Panos

unread,
Apr 5, 2010, 1:52:26 AM4/5/10
to awkcookbook
I don't believe that the CookBook, or any other project around awk
must take in account anything else except gawk. Awk has major ellipses
(like the lack of the in operator to check existence of array
elements, or the error "not an array" for looping on an empty array
etc). Standard old awk must be taken to the museum. The standard awk
is now gawk. If the development of awk (gawk) is going to take in
account every clone, then it'll soon get stucked. So, I suggest to
keep going with gawk and forget all other clones.

BTW, I'm expecting the indirect functions (Arnold is working hard on
that issue) too!
Have a nice day.

On 4 Απρ, 18:15, Michael Richter <ttmrich...@gmail.com> wrote:
> On my machine I have:
>

>    - gawk 3.1.6
>    - mawk 1.3.3
>    - jawk 1.02
>    - awk (version uncertain)


>
> The first two I did not install -- they were just there by default on my
> Ubuntu system.  Plain old original awk I installed out of curiosity and jawk
> I installed to ensure I have a decent awk implementation on my USB stick
> that I could run anywhere.
>
> I think that a cookbook for awk should probably give coverage in some form
> to the language family, not one particular dialect.  We should pick one
> (gawk, most likely, seeing as it's the most omnipresent) as
>

Lorance Stinson

unread,
Apr 6, 2010, 5:53:09 PM4/6/10
to awkco...@googlegroups.com
I will probably regret this but I must take exception to that. The old
standard AWK is still relevant and just as usable. I write plenty of
AWK scripts that conform to the old AWK and are perfectly usable. I
don't always assume I have a recent version of GAWK available, because
it is not. If this book is only going to consider GAWK then that is
fine by me. But I do not see GAWK as the one and only AWK left.

And there is a way to check if an element is in an array, just use in.

~# original-awk 'BEGIN {foo[1]=2;if(1 in foo){print "Foo!"}else{print
"NO foo"}}'
Foo!
~# original-awk 'BEGIN {foo[1]=2;if(2 in foo){print "Foo!"}else{print
"NO foo"}}'
NO foo

Tim Menzies

unread,
Apr 6, 2010, 8:19:59 PM4/6/10
to awkco...@googlegroups.com
i don't want to force anything or terminate an interesting discussion.
BUT i think our energies are being a little diverted. what is needed
now is arguments from experience based on the current code base- not
generalized discussions. the conversations i am seeing now are the
sort of thing we could have had 10 years ago and we could be having
them 10 years from now.

what we have, that is different, is the seed of one of the largest awk
libraries every written
(http://awk.googlecode.com/svn/trunk/src/release/cookbook.awk) by one
of the largest awk teams every assembled (i.e. us).

what do we need to do focus ourselves on useful extensions to that
library? for example,

1) how can we get on with lots of reviewing? e.g.
a) forget all my tools and my googlecode stuff then
b) add a comment box on each page like currently at awk.info?
c) we just debate things in blog format?

2) regarding the current discussion, can we end the current discussion
with something like "isolate the gawk specific things" in functions
(like zap), run with gawk, but leave commented on code for other
gawks. e.g.

function zap(a, i) {
# for(i in a) delete a[i] # for non-gawks
delete a
}

or (another one that should work with all awks)

function zap(a, i) {
split('',a,'')
}


t

p.s. i hope that's not too aggressive a suggestion. but i chaff. i
want us to get on with it

Reply all
Reply to author
Forward
0 new messages