bug-gawk
[Top][All Lists]
Advanced

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

Re: built-in functions are missed in non-awk namespaces


From: arnold
Subject: Re: built-in functions are missed in non-awk namespaces
Date: Mon, 29 Jul 2024 09:49:54 -0600
User-agent: Heirloom mailx 12.5 7/5/10

Hello.

Denis Shirokov <cosmogen@gmail.com> wrote:

> I found an error where many of the built-in functions are not visible from
> namespaces other than "awk".
>
> example:
>
> @namespace "some"
> BEGIN{
> print typeof( zz )
> }
>
> producing:
>
> gawk: ./bug.awk: fatal: function `some::typeof' not defined

This is not a bug. It is, in fact, clearly documented in the manual.
See https://www.gnu.org/software/gawk/manual/gawk.html#Naming-Rules.

> The namespace feature is interesting, but sadly there are many cases where
> it's too heavy to be used. I understand why this feature was implemented,
> but it's really too hard to write 'awk::...' every time when accessing the
> base resources.

It may be that you simply shouldn't use the feature, and then
you'll be happier. You need not use every feature that gawk has.

> - GREAT names may include only cased-up alpha characters.

This has been how awk has worked since the beginning, that
special variables are all upper-case.

> they should also include the underscore character (_).

I may consider making this change.

> I want my code to be clean and highly readable,

An admirable goal for which you should continue to strive.

> but names like IGNORECASE are just an eyesore.

It's too late to change that.

> Code readability is significantly hindered by the frequent use of 'awk::'
> from code located in other namespaces. Some functions are fundamental to
> programming in AWK and need to be accessible in a concise manner.

You can always write a forwarding function:

@namespace "some"
function _b(a, b, c, d) {
        return awk::_b(a, b, c, d)
}

You can even write a library file of such and simply @include it
where needed.

> add a new statement 'public' that makes names visible from any namespace

I'm afraid that's very unlikely to happen. Sorry.

> I apologize for not using the gawkbug program. I really don’t have the time
> to figure out what it is and where to obtain it.

It comes as part of the gawk distribution and installed with it.
At least on *nix systems.



reply via email to

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