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

GAWK Issue/question/curiosity #3: (calling built-in funcs indirectly)

34 views
Skip to first unread message

Kenny McCormack

unread,
Mar 26, 2015, 10:10:54 AM3/26/15
to
Calling built-in functions indirectly. The dox say you can't do this
(see below), but I thought we discussed this some time back and found that
it was (in a very late breaking fix) actually implemented (fixed).

BEGIN { s = "sin";print @s(1) }

Still generates a fatal error.

(I found the text below via Google, but it looks like it is not in 4.1.1, which
is, I believe, still the latest released version)

--- Cut Here ---
Hello all.

I have just implemented improvements so that indirect calls work to both
built-in functions and to extension functions:

$ cat i.awk
BEGIN {
Quarter_pi = 3.1415927 / 4
print sin(Quarter_pi)

f = "sin"
print @f(Quarter_pi)

print substr("abcdefgh", 2, 3)
f = "substr"
print @f("abcdefgh", 2, 3)
}
$ ./gawk -f i.awk
0.707107
0.707107
bcd
bcd

And for extension functions:

$ cat j.awk
@load "filefuncs"

BEGIN {
ret1 = stat(".", data1)
print "ret1 =", ret1

f = "stat"
ret2 = @f(".", data2)
print "ret2 =", ret2

for (i in data1) {
if (! isarray(data1[i])) {
print i, data1[i]
if (! (i in data2) || data1[i] != data2[i]) {
printf("mismatch element \"%s\"\n", i)
}
}
}
}

$ export AWKLIBPATH=$PWD/extension/.libs
$ ./gawk -f j.awk
ret1 = 0
ret2 = 0
blksize 4096
devbsize 512
mtime 1409812755
mode 16877
type directory
dev 2053
gid 1000
ino 10364600
ctime 1409812755
blocks 8
nlink 18
name .
atime 1409812758
pmode drwxr-xr-x
size 4096
uid 1000

The documentation has been updated and the code will be in the git
repo shortly.

Arnold
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com
P.O. Box 354 Home Phone: +972 8 979-0381
Nof Ayalon
D.N. Shimshon 9978500 ISRAEL
Vote Up! 0 Vote Down!
Report As Spam Reply arnold 9/4/2014
--- Cut Here ---

Kenny McCormack

unread,
Apr 7, 2015, 7:36:37 AM4/7/15
to
In article <mf141d$4se$4...@news.xmission.com>,
Bump!!!!

--
About that whole "sent His Son to die for us thing", I've never been able
to understand that one. It's not like Jesus isn't going back to Heaven
after his Earthly self dies, right? So, having him be executed, and
resurrect a few days later strikes me as being more akin to spending the
weekend at the non-custodial parent's house than "dying", doesn't it?

Andrew Schorr

unread,
Apr 7, 2015, 8:47:14 PM4/7/15
to
On Tuesday, April 7, 2015 at 7:36:37 AM UTC-4, Kenny McCormack wrote:
> Kenny McCormack wrote:
> >Calling built-in functions indirectly. The dox say you can't do this
> >(see below), but I thought we discussed this some time back and found that
> >it was (in a very late breaking fix) actually implemented (fixed).
> >
> > BEGIN { s = "sin";print @s(1) }
> >
> >Still generates a fatal error.
> >--- Cut Here ---
> >Hello all.
> >
> >I have just implemented improvements so that indirect calls work to both
> >built-in functions and to extension functions:
> >
>
> Bump!!!!

Didn't you answer your own question?

Regards,
Andy

Kenny McCormack

unread,
Apr 7, 2015, 9:18:53 PM4/7/15
to
In article <0e336e87-82df-4c0d...@googlegroups.com>,
I don't see that.

But I do see that this is going to be publicly available in 4.1.2 (soon to
be released).

What I didn't understand was how Arnold had said that he had fixed it, but
I didn't seem to have any way to get the fixed version.

But now I do. I think...

--
Modern Conservative: Someone who can take time out
from demanding more flag burning laws, more abortion
laws, more drug laws, more obscenity laws, and more
police authority to make warrantless arrests to remind
us that we need to "get the government off our backs".

Andrew Schorr

unread,
Apr 8, 2015, 7:39:35 PM4/8/15
to
On Tuesday, April 7, 2015 at 9:18:53 PM UTC-4, Kenny McCormack wrote:
> But I do see that this is going to be publicly available in 4.1.2 (soon to
> be released).
>
> What I didn't understand was how Arnold had said that he had fixed it, but
> I didn't seem to have any way to get the fixed version.
>
> But now I do. I think...

Patches and new features are initially available in the git repository. So if you want the most up-to-date version, you can always get it from there.
The basic procedure is:

git clone git://git.savannah.gnu.org/gawk.git
git checkout <desired branch>
./bootstrap.sh && ./configure && make

This new feature should be in the 4.1.2 release coming soonish.

Regards,
Andy



Kenny McCormack

unread,
Apr 8, 2015, 9:18:42 PM4/8/15
to
In article <6c2475b0-2228-4492...@googlegroups.com>,
Kewl!

--
"They shall be attended by boys graced with eternal youth, who to the
beholder?s eyes will seem like sprinkled pearls. When you gaze upon that
scene, you will behold a kingdom blissful and glorious."

--- Qur'an 76:19 ---
0 new messages