Re: array size vs index of last element (was Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context)

2023-05-29 Thread Chet Ramey
On 5/28/23 2:05 AM, Martin D Kealey wrote: On Tue, 23 May 2023 at 23:32, Chet Ramey wrote: On 5/22/23 10:56 PM, Martin D Kealey wrote: For example, if one is filling an array in random order, rather than progressively adding to the end, then it is useful and makes sense to be able to ask the

Re: array size vs index of last element (was Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context)

2023-05-28 Thread Robert Elz
Date:Sun, 28 May 2023 16:05:04 +1000 From:Martin D Kealey Message-ID: | PS: Everyone assumes that "the speed of external executables is the | limiting factor", but it turns out that's not true. It's possible to do | MUCH worse, just using built-in features:

array size vs index of last element (was Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context)

2023-05-27 Thread Martin D Kealey
On Tue, 23 May 2023 at 23:32, Chet Ramey wrote: > On 5/22/23 10:56 PM, Martin D Kealey wrote: > > > For example, if one is filling an array in random order, rather than > > progressively adding to the end, then it is useful and makes sense to be > > able to ask the array for its highest index. >

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-22 Thread Chet Ramey
On 5/21/23 5:01 PM, Martin D Kealey wrote: 1. ${array[@]:start:count} can under some circumstances return elements with indeces >= start+count, completely contravening expectations from other programming languages. There should be a `declare` or `local` option to fix that, and/or a shopt setting

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-22 Thread Chet Ramey
On 5/20/23 8:00 PM, Emanuele Torre wrote: This was already reported 12 and a half years ago, but there have not been many replies: https://lists.gnu.org/archive/html/bug-bash/2010-12/msg00128.html It seems more natural, especially in the presence of sparse arrays, to allow references to uns

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-22 Thread Oğuz
22 Mayıs 2023 Pazartesi tarihinde Martin D Kealey yazdı: > I disagree: this would constitute a major change, breaking behaviour that > is (for good reasons) depended on. > How so? I wouldn't expect expanding `a[1]' to not fail when `a[1]' is unset and `set -u' is in effect, and can't see why any

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-22 Thread Martin D Kealey
On Mon, 22 May 2023, 12:59 Emanuele Torre, wrote: > I am not really proposing a major change to the behaviour of nounset, I > am only pointing out the incorrect bash behaviour for that case. I disagree: this would constitute a major change, breaking behaviour that is (for good reasons) depended

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-21 Thread Emanuele Torre
On Mon, May 22, 2023 at 09:27:17AM +1000, Martin D Kealey wrote: > I just realised I expressed an opinion about associative arrays while the > original post was about indexed arrays. > I simply reported that, specifically in arithmetic contexts, when using a variable (not as the lhs of an = assig

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-21 Thread Martin D Kealey
I just realised I expressed an opinion about associative arrays while the original post was about indexed arrays. My take on this is that indexed arrays are almost always "dynamic"; while it's possible to use constant indices to emulate a struct, that is unusual. For most purposes the flexibility

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-21 Thread Greg Wooledge
On Mon, May 22, 2023 at 07:01:18AM +1000, Martin D Kealey wrote: > [...] and treating "unset" as a fatal error is not the experience that > programmers have using other scripting languages, and is therefore, I would > argue, not something that should be added to the Shell, and certainly not > as a

Re: setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-21 Thread Martin D Kealey
(I assume this is a continuation of the discussion in #bash on Libera.chat yesterday?) The primary use of `set -u` is to detect misspelled variable names, and misspelled keys for associative arrays seems like a reasonable extension of that, if you assume that they're in some sense a fixed list, li

setarray[unsetkey] doesn't trigger nounset in arithmetic context

2023-05-20 Thread Emanuele Torre
This was already reported 12 and a half years ago, but there have not been many replies: https://lists.gnu.org/archive/html/bug-bash/2010-12/msg00128.html The issue seems to be caused by expr_streval() only checking for unbound identifiers at this line: https://git.savannah.gnu.org/cgit/bash