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

Re: 'i' subscript flag



Bart Schaefer wrote:
> On Apr 2,  5:37pm, Anthony Charles wrote:
> }
> } man zshparam says: 
> } "i   Like `r', but gives the index of the match instead; this may not
> } be combined with a second argument."
> } 
> } I just wonder why this can't be combined with another flag which would
> } be useful in this case for example:
> } 
> } Saito% X="bar foo paz"
> } Saito% print $X[(i)p*]
> } 9
> } Saito% print $X[(wi)p*]
> } 9
> } 
> } but one may expect to get '3'. Is this a design choice?
> 
> In some sense, yes.  It has to do with the way that the internals of
> parameter expansion were originally implemented (long before any kind
> of reverse-subscripting was possible) and what it was reasonable to
> layer on top of that.
> 
> Since you can always do e.g.
> 
>     % print ${${=X}[(i)p*]}
>     3
> 
> it's not that significant a restriction.

It's still a rather confusing bug since there's no indication you can
can only do this with forward array indexing.

Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.44
diff -u -r1.44 params.yo
--- Doc/Zsh/params.yo	25 Mar 2008 17:47:11 -0000	1.44
+++ Doc/Zsh/params.yo	2 Apr 2008 16:53:16 -0000
@@ -190,7 +190,8 @@
 item(tt(w))(
 If the parameter subscripted is a scalar then this flag makes
 subscripting work on words instead of characters.  The default word
-separator is whitespace.
+separator is whitespace.  Currently this flag does not work
+with reverse subscripting (the tt(i), tt(I), tt(r) and tt(R) flags).
 )
 item(tt(s:)var(string)tt(:))(
 This gives the var(string) that separates words (for use with the

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author