Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Array slices (PWS's unposted Etc/NEWS change)



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