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: Andrew J. Schorr
Subject: Re: built-in functions are missed in non-awk namespaces
Date: Mon, 29 Jul 2024 11:49:16 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

Hi,

I believe this is documented in the manual here:

   https://www.gnu.org/software/gawk/manual/html_node/Naming-Rules.html

   Outside the awk namespace, the names of the additional gawk built-in 
functions (such as gensub() or strftime()) may be used as component names. The 
same set of names may be used as namespace names, although this has the 
potential to be confusing.

I can't readily find a list of such functions in the manual, but I think this
hack may work:

bash-5.1$ grep 'builtin.*GAWKX' awkgram.y 
{"adump",       Op_builtin,    LEX_BUILTIN,     GAWKX|A(1)|A(2)|DEBUG_USE,      
do_adump,       0},
{"and",         Op_builtin,    LEX_BUILTIN,     GAWKX,          do_and, 
MPF(and)},
{"asort",       Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   
do_asort,       0},
{"asorti",      Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   
do_asorti,      0},
{"bindtextdomain",      Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2),        
do_bindtextdomain,      0},
{"compl",       Op_builtin,    LEX_BUILTIN,     GAWKX|A(1),     do_compl,       
MPF(compl)},
{"dcgettext",   Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3),   
do_dcgettext,   0},
{"dcngettext",  Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2)|A(3)|A(4)|A(5), 
do_dcngettext,  0},
{"gensub",      Op_sub_builtin,  LEX_BUILTIN,   GAWKX|A(3)|A(4), 0,     0},
{"intdiv0",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(3),     do_intdiv,      
MPF(intdiv)},
{"isarray",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(1),     do_isarray,     
0},
{"lshift",      Op_builtin,    LEX_BUILTIN,     GAWKX|A(2),     do_lshift,      
MPF(lshift)},
{"mkbool",      Op_builtin,    LEX_BUILTIN,     GAWKX|A(1),     do_mkbool,      
0},
{"mktime",      Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2), do_mktime, 0},
{"or",          Op_builtin,    LEX_BUILTIN,     GAWKX,          do_or,  
MPF(or)},
{"patsplit",    Op_builtin,    LEX_BUILTIN,     GAWKX|A(2)|A(3)|A(4), 
do_patsplit,      0},
{"rshift",      Op_builtin,    LEX_BUILTIN,     GAWKX|A(2),     do_rshift,      
MPF(rshift)},
{"stopme",      Op_builtin,     LEX_BUILTIN,    GAWKX|A(0)|DEBUG_USE,   stopme, 
        0},
{"strftime",    Op_builtin,      LEX_BUILTIN,   GAWKX|A(0)|A(1)|A(2)|A(3), 
do_strftime, 0},
{"strtonum",    Op_builtin,    LEX_BUILTIN,     GAWKX|A(1),     do_strtonum, 
MPF(strtonum)},
{"systime",     Op_builtin,      LEX_BUILTIN,   GAWKX|A(0),     do_systime,     
0},
{"typeof",      Op_builtin,      LEX_BUILTIN,   GAWKX|A(1)|A(2), do_typeof,     
0},
{"xor",         Op_builtin,    LEX_BUILTIN,     GAWKX,          do_xor, 
MPF(xor)},

Regards,
Andy

On Mon, Jul 29, 2024 at 02:49:34PM +0300, Denis Shirokov wrote:
> Hello,
> 
> 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
> 
> the following is the list of built-in functions that are failing
> 
> typeof
> and
> or
> asort
> asorti
> gensub
> patsplit
> strtonum
> 
> version: GNU Awk 5.3.0, API 4.0
> platform: Windows 10 Pro (x64)
> 
> conclusions:
> 
> 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. Here are some mistakes, in my opinion, that are currently
> present in the namespace feature:
> 
> - GREAT names may include only cased-up alpha characters.
> 
> they should also include the underscore character (_).
> 
> I want my code to be clean and highly readable, but names like IGNORECASE
> are just an eyesore.
> 
> - awk:: names should be visible from all namespaces.
> 
> 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.
> 
> I hope that the following example is clear:
> 
> func _a( a, b, c, d ) {
> return a }
> func _b( a, b, c, d ) {
> return b }
> BEGIN{
> if ( _b( readfile( "..." ), ERRNO ) )     # looking good
> ... }
> @namespace "some"
> BEGIN{
> if ( awk::_b( readfile( "..." ), ERRNO ) )      # this is ugly
> ... }
> 
> proposed common solution:
> 
> add a new statement 'public' that makes names visible from any namespace
> 
> func Some() {
> ... }
> public Some, Arr, SuperGlobal
> @namespace "some"
> BEGIN{
> Arr[ ... ]
> Some( SuperGlobal ) }
> 
> just think about it :)
> 
> 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.
> 
> with the Best Regards
> Denis Shirokov



reply via email to

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