Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Array slices (PWS's unposted Etc/NEWS change)
- X-seq: zsh-workers 11716
- From: Wayne Davison <wayned@xxxxxxxxxxxxxxxxxxxxx>
- To: Zsh Workers <zsh-workers@xxxxxxxxxxxxxx>
- Subject: Re: Array slices (PWS's unposted Etc/NEWS change)
- Date: Thu, 1 Jun 2000 13:51:16 -0700 (PDT)
- In-reply-to: <1000601155002.ZM3182@xxxxxxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
On Thu, 1 Jun 2000, Bart Schaefer wrote:
> Unfortunately (?) that means $array[0,0] != $array[0].
This is quite easy to fix, so I think it should be. I've appended
a patch (which I will check into cvs momentarily).
> That patch has also caused the failure in the last example here:
> ---------------------------
> zagzig% foo=(a b c d e f g)
> zagzig% echo $foo[-4,1]
> d e f g
> ---------------------------
>
> Yowtch.
Ick. Negative start values combined with positive end values are
currently broken. This makes me think that I should have gone with
my alternative internal representation which was to change the end
position to be a 1-relative index (rather than the old 0-relative
index or the new length). I'll look into this to see what might be
the cleanest solution.
..wayne..
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Index: Src/params.c
@@ -941,7 +941,7 @@
r = isset(KSHARRAYS) ? 1 : 0;
} else {
r = mathevalarg(s, &s);
- if ((!r && !a2) || (isset(KSHARRAYS) && r >= 0))
+ if (isset(KSHARRAYS) && r >= 0)
r++;
}
if (word && !v->isarr) {
@@ -1185,19 +1185,19 @@
} else {
int com;
- if (start > 0)
- start--;
if ((com = (*s == ','))) {
s++;
len = getarg(&s, &inv, v, 1, &dummy);
if (len > 0) {
- len -= start;
+ len -= start - 1;
if (len < 0)
len = 0;
}
} else {
len = wlen ? wlen : 1;
}
+ if (start > 0)
+ start--;
if (*s == ']' || *s == Outbrack) {
s++;
if (v->isarr && len == 1 && !com &&
---8<------8<------8<------8<---cut here--->8------>8------>8------>8---
Messages sorted by:
Reverse Date,
Date,
Thread,
Author