bug-gawk
[Top][All Lists]
Advanced

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

Re: Indirect function calls in namespaces


From: arnold
Subject: Re: Indirect function calls in namespaces
Date: Fri, 03 Dec 2021 02:31:16 -0700
User-agent: Heirloom mailx 12.5 7/5/10

Hi.

Thank you for sending in a bug report.  Gawk does not work the way
you are expecting. Function name space "resolution" occurs entirely
at program parse time.  The function you are trying to call is "n::f".

The @namespace directive is simply a convenience that allows you to
type `function f()' instead of having to type 'function n::f()'.

You can see this if you loop through the indices of FUNCTAB.

Functions and variables in the "awk" namespace are not stored in the
symbol tables with the leading "awk::" prefix for backwards compatibility.
This design choice, I think, provides the right balance between convenience
and backwards compatibility, although it does complicate the code somewhat.

Thanks,

Arnold

Joep van Delft <jpvndlft@gmail.com> wrote:

> Hi,
>
> Consider this program:
>
> ========
> #!/usr/bin/env -S gawk -f
>
> @namespace "n"
>
> function f() { }
>
> BEGIN {
>   fun = "f"
>   @fun()
> }
> ========
>
> It errors with:
> gawk: ./namespace_indirect_fuction_call.awk:9: fatal: `f' is not a
> function, so it
> cannot be called indirectly
>
> Any of the following fixes it:
> - remove namespace
> - change namespace to "awk"
> - set 'fun = "n::f"'
>
> I would expect that the program would succeed, as the function name ought
> to be
> found inside the namespace without explicitly specifying it.
>
> Thanks,
>
> Joep



reply via email to

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