[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gensub() indirectly called with more than 2 parameters: produce a st
From: |
Denis Shirokov |
Subject: |
Re: gensub() indirectly called with more than 2 parameters: produce a strange error |
Date: |
Wed, 22 Jan 2025 18:00:55 +0200 |
i can somewhat understand why sub() and gsub() might be limited during
indirect calling (since they modify the contents of variables without an
assignment operation), but I absolutely don’t understand why gensub() falls
under the same criteria. I see no logical connection. How are we even
supposed to use gensub() with just two parameters? The documentation says
nothing about this regarding gensub(). What will be the effect of calling
gensub() with two parameters? Will the third parameter default to "g" or "G"?
What will serve as the data source for gensub()?
And in general, are you designing a good, flexible programming language, or
are you publishing a "list of rules" for using this language?
The same issue came up in a recent discussion about the behavior of the
length() function:
Why does length(A) make A unassigned instead of leaving it untyped?
Tradition? Guilty! By introducing, starting from gawk 5.2.2 (according to
the documentation), the ability for array elements to *exist* in an array
while remaining untyped, you blatantly break compatibility rules. For
example, when copying one array into another, old code will most likely
recreate the untyped elements in the target array as unassigned. You’re not
afraid to break tradition and compatibility there, but when it comes to
length(), you refer to some kind of tradition...
I’ve been programming in gawk for many years, but for some decisions
regarding the fate of this programming language, I simply cannot find
logical reasoning. I’m sorry, but that’s just how it is.
I don’t understand why gensub() has this peculiar limitation where indirect
calling is restricted to two parameters—who even came up with that idea?
Be that as it may, gawk has been growing and evolving very significantly in
recent years, and therefore I will accept any decision made by its
leadership. However, I would at least like to understand some of these
decisions...
Regards
Denis
ср, 22 янв. 2025 г. в 17:33, Denis Shirokov <cosmogen@gmail.com>:
> Great question!
>
> ср, 22 янв. 2025 г. в 16:29, Andrew J. Schorr <
> aschorr@telemetry-investments.com>:
>
>> Hi,
>>
>> Is that the issue, or is it that the indirect gensub call
>> is requiring 2 args instead of 3 or 4?
>>
>> In builtin.c:call_sub, the code says:
>>
>> if (flags == 0 || flags == GSUB) {
>> /* sub or gsub */
>> if (nargs != 2)
>> fatal(_("%s: can be called indirectly only with
>> two arguments"), name);
>> ...
>> } else {
>> /* gensub */
>> if (nargs < 3 || nargs > 4)
>> fatal(_("indirect call to gensub requires three
>> or four arguments"));
>>
>> So why is this insisting on only 2 args?
>>
>> Regards,
>> Andy
>>
>> On Wed, Jan 22, 2025 at 01:16:21AM -0700, arnold@skeeve.com wrote:
>> > "Arguments" is a synonym for "parameters". I will see if it makes
>> > sense to try to use only one term everywhere.
>> >
>> > Thanks,
>> >
>> > Arnold
>> >
>> > Denis Shirokov <cosmogen@gmail.com> wrote:
>> >
>> > > Hi GAWK Team!
>> > >
>> > > the built-in gensub() generate strange error in case if called
>> infirectly
>> > > with more than two parameters
>> > >
>> > > to reproduce this issue run attached (example.gwk) script using:
>> > >
>> > > gawk -f ./example.gwk
>> > >
>> > > example:
>> > >
>> > > BEGIN{
>> > > f = "awk::gensub"
>> > > a = b = c = d = ""
>> > > @f( a, b, c, d )
>> > > }
>> > >
>> > > outputs:
>> > >
>> > > gawk: ./example.gwk:7: fatal: awk::gensub: can be called
>> indirectly
>> > > only with two arguments
>> > >
>> > > two arguments? =(
>> > >
>> > > Regards
>> > > Denis
>>
>>