Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

AOK: a tiny object system in AWK

70 views
Skip to first unread message

timm

unread,
Mar 4, 2017, 9:47:24 PM3/4/17
to
Anyone got any interest/comment on the following simple object system in AOK? No inheritance or polymorphism but, hey, you can't have everything.

There's a whole tutorial on this at https://ttv1.github.io/aok/

A brief intro follows.

AOK is a pre-processor that converts

a.b.c

into

a["b"]["c"]

Very simple trick but it starts to make AWK code starting to look at lot like Python, Ruby, LUA etc.

For a simple example of AOK, the following Symbol constructor initializes something that tracks string frequency. Also, it keeps a handle on the most fr3quent string seen so far (the mode).

function Symbol(i) {
have(i,"count")
i.mode = ""
i.most = 0
}
function have(lst,key,fun) {
# ensure there is a list at key.
# recursively, build a nested structure with "fun", if supplied
lst[key][1];
delete lst[key][1]
if (fun) @fun(lst[key])
}

The interface to Symbols is the Symbol1 function that updates the count, mode etc.

function Symbol1(i,str, n) {
n = ++i.counts[str]
if (n > i.most) {
i.mode = str
i.most = n
}}





Marc de Bourget

unread,
Mar 5, 2017, 8:48:02 AM3/5/17
to
Hi Timm, interesting stuff, thank you!
0 new messages