zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <okiddle@yahoo.co.uk>
To: Jonathan Hankins <jonathan-hankins@mindspring.com>
Cc: zsh-workers@sunsite.dk
Subject: PATCH: Re: Subscript of negatively-subscripted array element gives incorrect result
Date: Tue, 30 Mar 2004 14:28:33 +0200	[thread overview]
Message-ID: <5774.1080649713@trentino.logica.co.uk> (raw)
In-Reply-To: <200403251956.00439.jonathan-hankins@mindspring.com>

On 25 Mar, Jonathan Hankins wrote:
> 
> I am getting different results taking a substring of the same array element 
> when I index it negatively than when I index it positively.  Here is an 
> example:

As Bart surmised, it was returning a one element array when negative
indexing was used. Fix is below:

Index: Src/params.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/params.c,v
retrieving revision 1.79
diff -u -r1.79 params.c
--- Src/params.c	18 Mar 2004 13:54:56 -0000	1.79
+++ Src/params.c	30 Mar 2004 12:09:58 -0000
@@ -1272,13 +1272,14 @@
 	    } else {
 		end = we ? we : start;
 	    }
+	    if (start != end) com = 1;
 	    if (start > 0)
 		start--;
 	    else if (start == 0 && end == 0)
 		end++;
 	    if (s == tbrack) {
 		s++;
-		if (v->isarr && start == end-1 && !com &&
+		if (v->isarr && !com &&
 		    (!(v->isarr & SCANPM_MATCHMANY) ||
 		     !(v->isarr & (SCANPM_MATCHKEY | SCANPM_MATCHVAL |
 				   SCANPM_KEYMATCH))))
Index: Test/D05array.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D05array.ztst,v
retrieving revision 1.1
diff -u -r1.1 D05array.ztst
--- Test/D05array.ztst	2 Apr 2001 12:34:23 -0000	1.1
+++ Test/D05array.ztst	30 Mar 2004 12:09:58 -0000
@@ -3,6 +3,7 @@
 %prep
 
   foo=(a b c d e f g)
+  arr=(foo bar baz)
   mkdir array.tmp
   touch array.tmp/{1..9}
 
@@ -60,6 +61,20 @@
 0:A slice with a negative start and end
 >.b c d e f.
 
+  echo .${${arr[2]}[1]}.
+  echo .${${arr[-2]}[1]}.
+  echo .${${arr[2,2]}[1]}.
+  echo .${${arr[-2,-2]}[1]}.
+  echo .${${arr[2,-2]}[1]}. 
+  echo .${${arr[-2,2]}[1]}. 
+0:slices should return an array, elements a scalar
+>.b.
+>.b.
+>.bar.
+>.bar.
+>.bar.
+>.bar.
+
   setopt ksh_arrays
   echo .${foo[1,2]}.
   unsetopt ksh_arrays


      parent reply	other threads:[~2004-03-30 12:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-26  1:56 Jonathan Hankins
2004-03-26  4:28 ` Bart Schaefer
2004-03-30 12:28 ` Oliver Kiddle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5774.1080649713@trentino.logica.co.uk \
    --to=okiddle@yahoo.co.uk \
    --cc=jonathan-hankins@mindspring.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).