From: Wayne Davison <wayned@users.sourceforge.net>
To: Bart Schaefer <schaefer@candle.brasslantern.com>
Cc: <zsh-workers@sunsite.dk>
Subject: Re: PATCH: Icky little array slice assignment bug
Date: Sat, 19 May 2001 05:13:55 -0700 (PDT) [thread overview]
Message-ID: <Pine.LNX.4.33L2.0105190449500.7240-200000@phong.blorf.net> (raw)
In-Reply-To: <1010518181629.ZM17512@candle.brasslantern.com>
[-- Attachment #1: Type: TEXT/PLAIN, Size: 1655 bytes --]
On Fri, 18 May 2001, Bart Schaefer wrote:
> zagzig% a=(x y z)
> zagzig% a[(I)q]=W
> zagzig% echo $a
> x y W x y z
I patched this in a similar way to your diff, but I also made a[(I)q]=W
prepend the 'W' to the array.
> x y W x y z V <-- this is ok
> zagzig% a[(R)q]=U
> zagzig% echo $a
> U y W x y z V <-- this is probably unexpected
This is because we currently have a[0] as an alias for a[1]. Did we
have a good reason for that? I think it would make more sense to have
a[0] return an empty string, while setting it should prepend an element
to the array. My appended patch goes this route.
> Well, whaddya know; you CAN do an "unshift", you just have to use a
> seemingly-impossible range to accomplish it.
You can also insert a new element anywhere with something like
"a[3,2]=middle". I think that this is a good thing.
> zagzig% a=(a b c)
> zagzig% a[2,(R)q]=x
> zagzig% echo $a
> a x a b c
Yeah, that's really non-intuitive, isn't it? You actually told zsh that
you wanted all elements before 2 ("a") before the new string, and all
the elements after 0, ("a b c") after the string. I think that this
should work the same as a[2,1] -- i.e. it should insert the string
without duplicating any existing elements. My patch also does this.
If we decide that changing a[0] is a bad idea, I can change $a[(R)q]
to return an empty string when there is no match (rather than the first
element of the array), and I could even make "a[(R)q]=prepend" work
without affecting "a[0]=newfirstelement". I had such a patch all worked
up when I decided that a[0] should just behave consistently no matter
where the 0 came from.
Thoughts?
..wayne..
[-- Attachment #2: Array fixes --]
[-- Type: TEXT/PLAIN, Size: 581 bytes --]
Index: Src/params.c
@@ -1252,8 +1252,6 @@
}
if (start > 0)
start--;
- else if (start == 0 && end == 0)
- end++;
if (s == tbrack) {
s++;
if (v->isarr && start == end-1 && !com &&
@@ -1721,8 +1719,13 @@
v->pm->nam, 0);
return;
}
- if (v->inv && unset(KSHARRAYS))
- v->start--, v->end--;
+ if (v->inv && unset(KSHARRAYS)) {
+ if (v->start > 0)
+ v->start--;
+ v->end--;
+ }
+ if (v->end < v->start)
+ v->end = v->start;
q = old = v->pm->gets.afn(v->pm);
n = arrlen(old);
if (v->start < 0) {
next prev parent reply other threads:[~2001-05-19 12:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-05-18 17:34 Bart Schaefer
2001-05-18 18:16 ` Bart Schaefer
2001-05-19 12:13 ` Wayne Davison [this message]
2001-05-20 9:25 ` Wayne Davison
2001-05-20 21:31 ` Bart Schaefer
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=Pine.LNX.4.33L2.0105190449500.7240-200000@phong.blorf.net \
--to=wayned@users.sourceforge.net \
--cc=schaefer@candle.brasslantern.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).