Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Professional wrestling: ballet for the common man.


devel / comp.lang.awk / (GAWK) fatal: attempt to use scalar 'x' as an array

SubjectAuthor
* (GAWK) fatal: attempt to use scalar 'x' as an arrayKenny McCormack
+* Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayJanis Papanagnou
|+* Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayJanis Papanagnou
||`* Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayKenny McCormack
|| +* Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayJ Naman
|| |`- [meta] Usenet conventions and Netiquette (was Re: (GAWK) fatal:Janis Papanagnou
|| `- Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayJanis Papanagnou
|`- Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayAharon Robbins
`* Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayAndrew Schorr
 +- Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayKenny McCormack
 `- Re: (GAWK) fatal: attempt to use scalar 'x' as an arrayAharon Robbins

1
(GAWK) fatal: attempt to use scalar 'x' as an array

<sf2ukj$nfnv$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=859&group=comp.lang.awk#859

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Thu, 12 Aug 2021 10:54:12 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sf2ukj$nfnv$1@news.xmission.com>
Injection-Date: Thu, 12 Aug 2021 10:54:12 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="769791"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 12 Aug 2021 10:54 UTC

Observe:

$ gawk4 '{ x[$1] = $0 } END { if (!length(x)) print "Nothing in the array";for (i in x) print i,x[i] }'
Nothing in the array
gawk4: cmd. line:1: fatal: attempt to use scalar `x' as an array
$

This happens because I hit ^D (eof) as the first input to this program.

I can "fix" this issue by either:
1) Entering at least one valid line of input before hitting EOF.
or
2) Reversing the order of the two clauses in the END section.

Now, of course, it is clear what is going on here - and why the "fixes"
work. But what surprises me is that it (the error) happens at all. My
understanding had been that the issue (i.e., dark corner in the GAWK
language) of whether something is an array or a scalar is resolved entirely
at compile time. That basically the context of a variable's first
occurrence determined its type (i.e., array or not). So:
1) Note that the first occurrence of x is in the assignment, so you'd
think it would get array'ized there.
2) I find it strange that the runtime execution path (whether or not
the assignment part ever executes) ends up determining the type of 'x'.

I find this interesting. It would be nice if this dark corner could be
removed from (fixed in) the language.

Note, incidentally, that TAWK is better here (as it [almost] always is).
This dark corner does not exist in TAWK. A variable can have multiple
types in the course of a program.

--
To most Christians, the Bible is like a software license. Nobody
actually reads it. They just scroll to the bottom and click "I agree."

- author unknown -

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<sf33g8$f3s$1@news-1.m-online.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=864&group=comp.lang.awk#864

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Thu, 12 Aug 2021 14:17:12 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 45
Message-ID: <sf33g8$f3s$1@news-1.m-online.net>
References: <sf2ukj$nfnv$1@news.xmission.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:713d:219:5d94:710f
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1628770632 15484 2001:a61:241e:cc01:713d:219:5d94:710f (12 Aug 2021 12:17:12 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Thu, 12 Aug 2021 12:17:12 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <sf2ukj$nfnv$1@news.xmission.com>
 by: Janis Papanagnou - Thu, 12 Aug 2021 12:17 UTC

On 12.08.2021 12:54, Kenny McCormack wrote:
> Observe:
>
> $ gawk4 '{ x[$1] = $0 } END { if (!length(x)) print "Nothing in the array";for (i in x) print i,x[i] }'
> Nothing in the array
> gawk4: cmd. line:1: fatal: attempt to use scalar `x' as an array
> $
>
> This happens because I hit ^D (eof) as the first input to this program.
>
> I can "fix" this issue by either:
> 1) Entering at least one valid line of input before hitting EOF.
> or
> 2) Reversing the order of the two clauses in the END section.

or
3) Force x to become an array.

I recall a similar question from mine a couple months ago (you were
amongst the first responders, BTW), and my try on a solution was code
like the one in the BEGIN clause added to your test case:

gawk '
BEGIN { x["dummy"] ; delete x["dummy"] }
{ x[$1] = $0 }
END { if (!length(x)) print "Nothing in the array"
for (i in x) print i,x[i]
}
'

>
> Now, of course, it is clear what is going on here - and why the "fixes"
> work. But what surprises me is that it (the error) happens at all. My
> understanding had been that the issue (i.e., dark corner in the GAWK
> language) of whether something is an array or a scalar is resolved entirely
> at compile time.

I don't think so. I think it's a pure runtime issue.

Janis

> [...]

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<sf392n$gnd$1@news-1.m-online.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=867&group=comp.lang.awk#867

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!4.us.feeder.erje.net!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Thu, 12 Aug 2021 15:52:23 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 26
Message-ID: <sf392n$gnd$1@news-1.m-online.net>
References: <sf2ukj$nfnv$1@news.xmission.com>
<sf33g8$f3s$1@news-1.m-online.net>
NNTP-Posting-Host: 2001:a61:241e:cc01:713d:219:5d94:710f
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1628776343 17133 2001:a61:241e:cc01:713d:219:5d94:710f (12 Aug 2021 13:52:23 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Thu, 12 Aug 2021 13:52:23 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
In-Reply-To: <sf33g8$f3s$1@news-1.m-online.net>
 by: Janis Papanagnou - Thu, 12 Aug 2021 13:52 UTC

On 12.08.2021 14:17, Janis Papanagnou wrote:
>
> or
> 3) Force x to become an array.

I just recall that, I think it was Ed who suggested a less bulky form.

BEGIN { delete x[""] }

works, and it seems

BEGIN { delete x }

works as well (at least in my GNU Awk context).

>
> gawk '
> BEGIN { x["dummy"] ; delete x["dummy"] }
> { x[$1] = $0 }
> END { if (!length(x)) print "Nothing in the array"
> for (i in x) print i,x[i]
> }
> '

Janis

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<sf3ll4$nonq$2@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=873&group=comp.lang.awk#873

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Thu, 12 Aug 2021 17:27:00 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sf3ll4$nonq$2@news.xmission.com>
References: <sf2ukj$nfnv$1@news.xmission.com> <sf33g8$f3s$1@news-1.m-online.net> <sf392n$gnd$1@news-1.m-online.net>
Injection-Date: Thu, 12 Aug 2021 17:27:00 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="779002"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Thu, 12 Aug 2021 17:27 UTC

In article <sf392n$gnd$1@news-1.m-online.net>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>On 12.08.2021 14:17, Janis Papanagnou wrote:
>>
>> or
>> 3) Force x to become an array.
>
>I just recall that, I think it was Ed who suggested a less bulky form.
>
> BEGIN { delete x[""] }
>
>works, and it seems
>
> BEGIN { delete x }
>
>works as well (at least in my GNU Awk context).

So, the point is, it really does just boil down to: You have to ensure
that, whatever execution path your program takes, the first runtime
reference to the variable is an unequivocally array context.

It strikes me that it might be a good thing for GAWK to have a "declare"
statement - that would allow you to state up front that something is an
array. Bash has this now, and it is actually quite useful.

--
A racist, a Nazi, and a Klansman walk into a bar...

Bartender says, "What will it be, Mr. Trump?"

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<76b1a0dd-0aea-4636-a55a-580a3c987735n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=874&group=comp.lang.awk#874

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:620a:29cf:: with SMTP id s15mr6041933qkp.363.1628792225689;
Thu, 12 Aug 2021 11:17:05 -0700 (PDT)
X-Received: by 2002:a25:2d0:: with SMTP id 199mr5957860ybc.123.1628792225429;
Thu, 12 Aug 2021 11:17:05 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!proxad.net!feeder1-2.proxad.net!209.85.160.216.MISMATCH!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Thu, 12 Aug 2021 11:17:05 -0700 (PDT)
In-Reply-To: <sf3ll4$nonq$2@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=96.255.253.97; posting-account=BcR7vAoAAABY9YgIIYIhD68t7wwjMvJW
NNTP-Posting-Host: 96.255.253.97
References: <sf2ukj$nfnv$1@news.xmission.com> <sf33g8$f3s$1@news-1.m-online.net>
<sf392n$gnd$1@news-1.m-online.net> <sf3ll4$nonq$2@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <76b1a0dd-0aea-4636-a55a-580a3c987735n@googlegroups.com>
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
From: jnaman2@gmail.com (J Naman)
Injection-Date: Thu, 12 Aug 2021 18:17:05 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
 by: J Naman - Thu, 12 Aug 2021 18:17 UTC

On Thursday, 12 August 2021 at 13:27:01 UTC-4, Kenny McCormack wrote:
> In article <sf392n$gnd$1...@news-1.m-online.net>,
> Janis Papanagnou <janis_pa...@hotmail.com> wrote:
> >On 12.08.2021 14:17, Janis Papanagnou wrote:
> >>
> >> or
> >> 3) Force x to become an array.
> >
> >I just recall that, I think it was Ed who suggested a less bulky form.
> >
> > BEGIN { delete x[""] }
> >
> >works, and it seems
> >
> > BEGIN { delete x }
> >
> >works as well (at least in my GNU Awk context).
> So, the point is, it really does just boil down to: You have to ensure
> that, whatever execution path your program takes, the first runtime
> reference to the variable is an unequivocally array context.
>
> It strikes me that it might be a good thing for GAWK to have a "declare"
> statement - that would allow you to state up front that something is an
> array. Bash has this now, and it is actually quite useful.
>
> --
> A racist, a Nazi, and a Klansman walk into a bar...
>
> Bartender says, "What will it be, Mr. Trump?"
Kenny McCormack: Would you PLEASE stop inserting political content into our conversations about the awk language! I don't care what ideology people espouse, I participate in this group to NOT have politics and ideology intrude on my conversations. Take your flames to Twitter ...

[meta] Usenet conventions and Netiquette (was Re: (GAWK) fatal: attempt to use scalar 'x' as an array)

<sf4fgf$rlm$1@news-1.m-online.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=876&group=comp.lang.awk#876

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: [meta] Usenet conventions and Netiquette (was Re: (GAWK) fatal:
attempt to use scalar 'x' as an array)
Date: Fri, 13 Aug 2021 02:48:15 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 34
Message-ID: <sf4fgf$rlm$1@news-1.m-online.net>
References: <sf2ukj$nfnv$1@news.xmission.com>
<sf33g8$f3s$1@news-1.m-online.net> <sf392n$gnd$1@news-1.m-online.net>
<sf3ll4$nonq$2@news.xmission.com>
<76b1a0dd-0aea-4636-a55a-580a3c987735n@googlegroups.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:6467:c665:485c:d115
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1628815695 28342 2001:a61:241e:cc01:6467:c665:485c:d115 (13 Aug 2021 00:48:15 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Fri, 13 Aug 2021 00:48:15 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <76b1a0dd-0aea-4636-a55a-580a3c987735n@googlegroups.com>
 by: Janis Papanagnou - Fri, 13 Aug 2021 00:48 UTC

On 12.08.2021 20:17, J Naman wrote:
> On Thursday, 12 August 2021 at 13:27:01 UTC-4, Kenny McCormack wrote:
>> [...]
> Kenny McCormack: Would you PLEASE stop inserting political content into our conversations about the awk language! I don't care what ideology people espouse, I participate in this group to NOT have politics and ideology intrude on my conversations. Take your flames to Twitter ...

J Naman, please comply to the Usenet posting standards yourself - here:
line length - before you even try to ask others to change their posting
habits.

This is Usenet, not a web forum or a Google forum. If you'd been using
a Real Newsreader you'd certainly be better aware of that fact. Then
you'd also see that the text you were addressing was part of a randomly
generated signature, not part of the topical post/conversation. (A real
newsreader would make that quite obvious, BTW; signatures are displayed
differently and are not inserted in quoted replies, for example.)

Since we're at it, Laurent, you too, get informed about Usenet and try
complying to Netiquette; post context. Get informed!

Other Google users flooding Usenet newsgroups should check the Usenet
Netiquette as well before continuing to post. It's sad that even long
time regulars here that switched to the Google interface forgot about
where they are and about the Netiquette.

I'm too old to really care, but if all those Googlies (Google Usenet-
newbies) start to try enforcing their own rules while not complying to
long time existing Usenet Netiquette it's time to speak up.

(Google users will know how to use the [Google] search engine to find
the Netiquette and information about Usenet newsgroups, so I abstain
from doing their homework and providing the link.)

Janis

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<sf4gce$s0k$1@news-1.m-online.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=877&group=comp.lang.awk#877

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!news.mixmin.net!news2.arglkargh.de!news.karotte.org!news.space.net!news.m-online.net!.POSTED!not-for-mail
From: janis_papanagnou@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.awk
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Fri, 13 Aug 2021 03:03:03 +0200
Organization: (posted via) M-net Telekommunikations GmbH
Lines: 44
Message-ID: <sf4gce$s0k$1@news-1.m-online.net>
References: <sf2ukj$nfnv$1@news.xmission.com>
<sf33g8$f3s$1@news-1.m-online.net> <sf392n$gnd$1@news-1.m-online.net>
<sf3ll4$nonq$2@news.xmission.com>
NNTP-Posting-Host: 2001:a61:241e:cc01:6467:c665:485c:d115
Mime-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
X-Trace: news-1.m-online.net 1628816590 28692 2001:a61:241e:cc01:6467:c665:485c:d115 (13 Aug 2021 01:03:10 GMT)
X-Complaints-To: news@news-1.m-online.net
NNTP-Posting-Date: Fri, 13 Aug 2021 01:03:10 +0000 (UTC)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
X-Enigmail-Draft-Status: N1110
In-Reply-To: <sf3ll4$nonq$2@news.xmission.com>
 by: Janis Papanagnou - Fri, 13 Aug 2021 01:03 UTC

On 12.08.2021 19:27, Kenny McCormack wrote:
> In article <sf392n$gnd$1@news-1.m-online.net>,
> Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>> On 12.08.2021 14:17, Janis Papanagnou wrote:
>>>
>>> or
>>> 3) Force x to become an array.
>>
>> I just recall that, I think it was Ed who suggested a less bulky form.
>>
>> BEGIN { delete x[""] }
>>
>> works, and it seems
>>
>> BEGIN { delete x }
>>
>> works as well (at least in my GNU Awk context).
>
> So, the point is, it really does just boil down to: You have to ensure
> that, whatever execution path your program takes, the first runtime
> reference to the variable is an unequivocally array context.
>
> It strikes me that it might be a good thing for GAWK to have a "declare"
> statement - that would allow you to state up front that something is an
> array. Bash has this now, and it is actually quite useful.

Well, part of the beauty of Awk is it's terseness, here the fact that
you don't need declarations. Of course the feature could be optional,
but then you'd have to introduce another keyword, something language
designers usually want to avoid. Declarations are especially useful
where a lot of data structuring features are present. GNU Awk started
to enter that path already by the support of multi-dimensional arrays,
so maybe, depending on any further plans to introduce yet more data
structuring features, a 'declare' might eventually be the consequence.
For the current primitive vs. compound data type dichotomy it's likely
just overkill, especially since there's a code pattern to address that
issue.

(It's a bit different in shells, with Bash's declare or Ksh's typeset;
typeset, for example, is a much more powerful concept than a simple
array/string/numeric declaration.)

Janis

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<d3603a3b-96fb-441c-9032-e06ad93d7fddn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=878&group=comp.lang.awk#878

  copy link   Newsgroups: comp.lang.awk
X-Received: by 2002:a05:620a:138a:: with SMTP id k10mr6049409qki.472.1628818461352;
Thu, 12 Aug 2021 18:34:21 -0700 (PDT)
X-Received: by 2002:a25:d052:: with SMTP id h79mr8870820ybg.246.1628818461029;
Thu, 12 Aug 2021 18:34:21 -0700 (PDT)
Path: i2pn2.org!i2pn.org!aioe.org!news.uzoreto.com!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.awk
Date: Thu, 12 Aug 2021 18:34:20 -0700 (PDT)
In-Reply-To: <sf2ukj$nfnv$1@news.xmission.com>
Injection-Info: google-groups.googlegroups.com; posting-host=38.76.0.51; posting-account=n5ws7AoAAADMJDAWfsygCPkNAonhHPfT
NNTP-Posting-Host: 38.76.0.51
References: <sf2ukj$nfnv$1@news.xmission.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <d3603a3b-96fb-441c-9032-e06ad93d7fddn@googlegroups.com>
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
From: aschorr@telemetry-investments.com (Andrew Schorr)
Injection-Date: Fri, 13 Aug 2021 01:34:21 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 2143
 by: Andrew Schorr - Fri, 13 Aug 2021 01:34 UTC

On Thursday, August 12, 2021 at 6:54:14 AM UTC-4, Kenny McCormack wrote:
> Observe:
>
> $ gawk4 '{ x[$1] = $0 } END { if (!length(x)) print "Nothing in the array";for (i in x) print i,x[i] }'
> Nothing in the array
> gawk4: cmd. line:1: fatal: attempt to use scalar `x' as an array
> $

As others have pointed out, adding 'delete x' essentially declares it as an array.
That being said, there seems to be a patch in the development tree that fixes this issue.
In gawk 5.1.0:

bash-4.2$ ./gawk '{ x[$1] = $0 } END { if (!length(x)) print "Nothing in the array";for (i in x) print i,x[i]; print typeof(x) }' < /dev/null
Nothing in the array
gawk: cmd. line:1: fatal: attempt to use scalar `x' as an array

In the master branch:

bash-4.2$ ./gawk '{ x[$1] = $0 } END { if (!length(x)) print "Nothing in the array";for (i in x) print i,x[i]; print typeof(x) }' < /dev/null
Nothing in the array
array

So this problem may eventually go away. But it is safest to say 'delete x' to avoid ambiguity.

Regards,
Andy

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<sf4mgc$oaa0$1@news.xmission.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=879&group=comp.lang.awk#879

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.awk
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Fri, 13 Aug 2021 02:47:40 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sf4mgc$oaa0$1@news.xmission.com>
References: <sf2ukj$nfnv$1@news.xmission.com> <d3603a3b-96fb-441c-9032-e06ad93d7fddn@googlegroups.com>
Injection-Date: Fri, 13 Aug 2021 02:47:40 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="796992"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Fri, 13 Aug 2021 02:47 UTC

In article <d3603a3b-96fb-441c-9032-e06ad93d7fddn@googlegroups.com>,
Andrew Schorr <aschorr@telemetry-investments.com> wrote:
....
>In the master branch:
>
>bash-4.2$ ./gawk '{ x[$1] = $0 } END { if (!length(x)) print "Nothing in the
>array";for (i in x) print i,x[i]; print typeof(x) }' < /dev/null
>Nothing in the array
>array

This is good. I am glad to see that it is being worked on.

I think we can all agree that while it is not a big deal in the grand
scheme of things, and we all know by now how to workaround it, it is in the
category of "surprising" and it would be better if it didn't happen.

>So this problem may eventually go away. But it is safest to say 'delete x' to
>avoid ambiguity.

For me, it was easiest to just reverse the order of the two clauses in the
END section (*). The idea of putting a BEGIN clause in (which my program
does not currently have) and to put the obscure incantation of "delete x"
there seems odd. Not necessarily bad, but odd.

(*) It was actually pretty much just by accident that I coded it in that
order originally. It could just as easily have been coded the other way
from the start.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/FreeCollege

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<sf6igd$1g8t$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=883&group=comp.lang.awk#883

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!BQLC9RhkgHDnVorCRJBs3Q.user.46.165.242.75.POSTED!not-for-mail
From: arnold@skeeve.com (Aharon Robbins)
Newsgroups: comp.lang.awk
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Fri, 13 Aug 2021 19:51:41 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sf6igd$1g8t$1@gioia.aioe.org>
References: <sf2ukj$nfnv$1@news.xmission.com> <sf33g8$f3s$1@news-1.m-online.net>
Injection-Info: gioia.aioe.org; logging-data="49437"; posting-host="BQLC9RhkgHDnVorCRJBs3Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Originator: arnold@skeeve.com (Arnold Robbins)
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
 by: Aharon Robbins - Fri, 13 Aug 2021 19:51 UTC

In article <sf33g8$f3s$1@news-1.m-online.net>,
Janis Papanagnou <janis_papanagnou@hotmail.com> wrote:
>> Now, of course, it is clear what is going on here - and why the "fixes"
>> work. But what surprises me is that it (the error) happens at all. My
>> understanding had been that the issue (i.e., dark corner in the GAWK
>> language) of whether something is an array or a scalar is resolved entirely
>> at compile time.
>
>I don't think so. I think it's a pure runtime issue.

This is correct, it is a pure runtime issue.
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com

Re: (GAWK) fatal: attempt to use scalar 'x' as an array

<sf6iom$1u0r$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=884&group=comp.lang.awk#884

  copy link   Newsgroups: comp.lang.awk
Path: i2pn2.org!i2pn.org!aioe.org!BQLC9RhkgHDnVorCRJBs3Q.user.46.165.242.75.POSTED!not-for-mail
From: arnold@skeeve.com (Aharon Robbins)
Newsgroups: comp.lang.awk
Subject: Re: (GAWK) fatal: attempt to use scalar 'x' as an array
Date: Fri, 13 Aug 2021 19:56:06 -0000 (UTC)
Organization: Aioe.org NNTP Server
Message-ID: <sf6iom$1u0r$1@gioia.aioe.org>
References: <sf2ukj$nfnv$1@news.xmission.com> <d3603a3b-96fb-441c-9032-e06ad93d7fddn@googlegroups.com>
Injection-Info: gioia.aioe.org; logging-data="63515"; posting-host="BQLC9RhkgHDnVorCRJBs3Q.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
Originator: arnold@skeeve.com (Arnold Robbins)
X-Notice: Filtered by postfilter v. 0.9.2
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
 by: Aharon Robbins - Fri, 13 Aug 2021 19:56 UTC

In article <d3603a3b-96fb-441c-9032-e06ad93d7fddn@googlegroups.com>,
Andrew Schorr <aschorr@telemetry-investments.com> wrote:
>In the master branch:
>
>bash-4.2$ ./gawk '{ x[$1] = $0 } END { if (!length(x)) print "Nothing in
>the array";for (i in x) print i,x[i]; print typeof(x) }' < /dev/null
>Nothing in the array
>array
>
>So this problem may eventually go away. But it is safest to say 'delete
>x' to avoid ambiguity.

Using 'delete x', or some other way to force x to be an array is the
most portable thing to do.

The fix in the development branch is that `length(x)' on a never
assigned value no longer forces that value to be a scalar, but leaves
it as undefined, and returns 0, which is correct both for undefined
scalars and undefined arrays.

This will be included in the next release.
--
Aharon (Arnold) Robbins arnold AT skeeve DOT com

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor