Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: ${a[(i)pattern]} if a=()
- X-seq: zsh-workers 24723
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxxxxx>
- Subject: Re: ${a[(i)pattern]} if a=()
- Date: Tue, 18 Mar 2008 12:13:30 +0000
- In-reply-to: Message from Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> of "Sun, 16 Mar 2008 17:59:46 MST." <080316175946.ZM10427@xxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxx; run by ezmlm
Bart Schaefer wrote:
> On Mar 16, 11:23pm, Stephane Chazelas wrote:
> }
> } > I think it's supposed to return 0 because it didn't match. 1 indicates
> } > it matched the first array element.
> } [...]
> }
> } According to the manual:
> }
> } matching key found is the result. On failure substitutes one more
> } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> } than the last currently valid index, as discussed under the
> } ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> } description of `r'.
> } ^^^^^^^^^^^^^^^^^^^
> The reason we're getting into trouble here is because there is *no* valid
> index when the array is empty. 0 is no longer a "currently valid index",
> so to return "one more than the last" is in some sense also invalid, and
> zero is the only index that is always invalid (barring KSH_* behavior).
>
> My personal opinion is that Stephane has the right of it here, and this
> empty-array case is just one that we missed way back when we added the
> "missing (i) falls of the top end" behavior.
I've read through the manual again, and you're right, the sense of it is
it should be one, because it's "off the end". As Stephane pointed out,
zero looks screwy here (whatever the arguments about validity of
indices). So you should commit the patch.
The one that should definitely return zero is (I), but it does. This is
where the ambiguity was in the past, since there was no "off the beginning".
--
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
Messages sorted by:
Reverse Date,
Date,
Thread,
Author