zsh-workers
 help / color / mirror / code / Atom feed
* Re: wrong array range with (r) flag on scalar?
       [not found] ` <150305084408.ZM20963@torch.brasslantern.com>
@ 2015-03-05 17:06   ` Peter Stephenson
  2015-03-08 22:53     ` Han Pingtian
  0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2015-03-05 17:06 UTC (permalink / raw)
  To: zsh-workers

couldn't resist rubbing it in at the end :-)

pws


diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
index d044f87..7b127bc 100644
--- a/Doc/Zsh/params.yo
+++ b/Doc/Zsh/params.yo
@@ -187,7 +187,17 @@ from the end of the array tt(foo), and
 Subscripting may also be performed on non-array values, in which
 case the subscripts specify a substring to be extracted.
 For example, if tt(FOO) is set to `tt(foobar)', then
-`tt(echo $FOO[2,5])' prints `tt(ooba)'.
+`tt(echo $FOO[2,5])' prints `tt(ooba)'.  Note that
+some forms of subscripting described below perform pattern matching,
+and in that case the substring extends from the start of the match
+of the first subscript to the end of the match of the second
+subscript.  For example,
+
+example(string="abcdefghijklm"
+print ${string[+LPAR()r+RPAR()d?,+LPAR()r+RPAR()h?]})
+
+prints `tt(defghi)'.  This is an obvious generalisation of the
+rule for single-character matches.
 
 subsect(Array Element Assignment)
 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: wrong array range with (r) flag on scalar?
  2015-03-05 17:06   ` wrong array range with (r) flag on scalar? Peter Stephenson
@ 2015-03-08 22:53     ` Han Pingtian
  2015-03-09 16:37       ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Han Pingtian @ 2015-03-08 22:53 UTC (permalink / raw)
  To: zsh-workers

On Thu, Mar 05, 2015 at 05:06:38PM +0000, Peter Stephenson wrote:
> couldn't resist rubbing it in at the end :-)
> 
> pws
> 
> 
> diff --git a/Doc/Zsh/params.yo b/Doc/Zsh/params.yo
> index d044f87..7b127bc 100644
> --- a/Doc/Zsh/params.yo
> +++ b/Doc/Zsh/params.yo
> @@ -187,7 +187,17 @@ from the end of the array tt(foo), and
>  Subscripting may also be performed on non-array values, in which
>  case the subscripts specify a substring to be extracted.
>  For example, if tt(FOO) is set to `tt(foobar)', then
> -`tt(echo $FOO[2,5])' prints `tt(ooba)'.
> +`tt(echo $FOO[2,5])' prints `tt(ooba)'.  Note that
> +some forms of subscripting described below perform pattern matching,
> +and in that case the substring extends from the start of the match
> +of the first subscript to the end of the match of the second
> +subscript.  For example,
> +
> +example(string="abcdefghijklm"
> +print ${string[+LPAR()r+RPAR()d?,+LPAR()r+RPAR()h?]})
> +
> +prints `tt(defghi)'.  This is an obvious generalisation of the
> +rule for single-character matches.
> 
>  subsect(Array Element Assignment)
> 

Looks like this is also the case for (i):

localhost% foo=abcdefgh
localhost% print $foo[(r)ab,(i)fg]
abcdefg
localhost%

Though 

localhost% print $foo[(i)fg]
6
localhost%

But according to the new contents of manual, this is the same case as
"(r)fg".

Thanks.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: wrong array range with (r) flag on scalar?
  2015-03-08 22:53     ` Han Pingtian
@ 2015-03-09 16:37       ` Bart Schaefer
  0 siblings, 0 replies; 3+ messages in thread
From: Bart Schaefer @ 2015-03-09 16:37 UTC (permalink / raw)
  To: zsh-workers

On Mar 9,  6:53am, Han Pingtian wrote:
}
} Looks like this is also the case for (i):
} 
} localhost% foo=abcdefgh
} localhost% print $foo[(r)ab,(i)fg]
} abcdefg
} localhost%
} 
} Though 
} 
} localhost% print $foo[(i)fg]
} 6
} localhost%
} 
} But according to the new contents of manual, this is the same case as
} "(r)fg".

You can't use (i) in ranges.  $s[(i)ab,(i)fg] is an "invalid subscript";
the end of the range is not treated the same as the start.

So although $s[(r)fg] is the same as $s[$s[(i)fg]], $s[(r)ab,(r)fg] is
not the same as $s[$s[(i)ab],$s[(i)fg]].

The foregoing of course all applies only to indexes on scalars; for an
index on an array, the pattern match and resulting index values apply
to entire array elements, so there are no substrings to extract.


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-03-09 16:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20150305083000.GA3294@localhost.localdomain>
     [not found] ` <150305084408.ZM20963@torch.brasslantern.com>
2015-03-05 17:06   ` wrong array range with (r) flag on scalar? Peter Stephenson
2015-03-08 22:53     ` Han Pingtian
2015-03-09 16:37       ` Bart Schaefer

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).