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

Re: string range between 1 and 0.



In article <990719050457.ZM8827@xxxxxxxxxxxxxxxxxxxxxxx>,
  "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> writes:

> That scheme wouldn't work in ksh mode in any case ... ${buffer[0,-1]} is
> the whole buffer, not the empty string.

I agree. ksharrays makes the scheme damaged.

> The difficulty with doing this is that C arrays are indexed from 0.  So
> when zsh uses 1-based indices, it has to decrement them before indexing
> into the internal representation of the value.  This decrement is done
> at parse time (unless the value is already zero), so that thereafter the
> same code can be used for ksh and zsh arrays.  Since negative numbers
> are already used for indexing back from the end, there isn't any value
> to represent the nonexistent position, which is in effect what you're
> asking for (because the only position to the left of the leftmost is
> the one that doesn't exist).

I understand that my expectation is not so trivial.

> If you represent the null region by unsetting pos2 or setting it empty,
> you can do this:
> 
> 	${pos2:+$buffer[pos1,pos2]}

I found another tricky answer.

  $buffer[pos2 == 0 ? 2 : pos1, pos2]

Hm. Arithmetic evaluation has the much closer syntax to ordinary
language such as perl or C. It's good. I feel regret that it cannot
handle objects other than integers.
-- 
Tanaka Akira



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