* Subscript of negatively-subscripted array element gives incorrect result
@ 2004-03-26 1:56 Jonathan Hankins
2004-03-26 4:28 ` Bart Schaefer
2004-03-30 12:28 ` PATCH: " Oliver Kiddle
0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Hankins @ 2004-03-26 1:56 UTC (permalink / raw)
To: zsh-workers
Hi,
I reported this previously through the Bugs section on the Sourceforge page
for zsh, but wasn't sure if it was active. I also have a bit more
information.
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:
These are correct:
% t=(foo bar baz)
% print ${t[2]}
bar
% print ${${t[2]}[1]}
b
% print ${${t[2]}[1,2]}
ba
% print ${${t[2]}[2]}
a
% print ${${t[2]}[2,3]}
ar
%
This is also correct:
% print ${t[-2]}
bar
These are not correct:
% print ${${t[-2]}[1]}
bar
% print ${${t[-2]}[1,2]}
bar
% print ${${t[-2]}[2]}
% print ${${t[-2]}[2,3]}
%
Those last 2 yield an empty string.
I verified this behavior with 4.0.4, 4.0.9, 4.1.1 and 4.2.0 on a Debian
GNU/Linux system.
Thanks!
-Jonathan Hankins
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Subscript of negatively-subscripted array element gives incorrect result
2004-03-26 1:56 Subscript of negatively-subscripted array element gives incorrect result Jonathan Hankins
@ 2004-03-26 4:28 ` Bart Schaefer
2004-03-30 12:28 ` PATCH: " Oliver Kiddle
1 sibling, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2004-03-26 4:28 UTC (permalink / raw)
To: zsh-workers
On Mar 25, 7:56pm, 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.
At first glance, it appears to be the case that positive-indexing returns
a scalar whereas negative indexing returns a one-element array.
^ permalink raw reply [flat|nested] 3+ messages in thread
* PATCH: Re: Subscript of negatively-subscripted array element gives incorrect result
2004-03-26 1:56 Subscript of negatively-subscripted array element gives incorrect result Jonathan Hankins
2004-03-26 4:28 ` Bart Schaefer
@ 2004-03-30 12:28 ` Oliver Kiddle
1 sibling, 0 replies; 3+ messages in thread
From: Oliver Kiddle @ 2004-03-30 12:28 UTC (permalink / raw)
To: Jonathan Hankins; +Cc: zsh-workers
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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2004-03-30 12:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-26 1:56 Subscript of negatively-subscripted array element gives incorrect result Jonathan Hankins
2004-03-26 4:28 ` Bart Schaefer
2004-03-30 12:28 ` PATCH: " Oliver Kiddle
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).