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

Re: string range between 1 and 0.



In article <990719000259.ZM8741@xxxxxxxxxxxxxxxxxxxxxxx>,
  "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx> writes:

> This is a side-effect of ksh array compatibility, believe it or not.

Hm.

> So, given the choices
>     (1) leave it as is
>     (2) treat [n,0] as [n,-1]
>     (3) treat [n,0] as an error
> my own preference is for (1).

I encount this problem with the code such as:

region="$buffer[pos1,pos2]"

I represent a region by pos1 and pos2.
To represent null region, I assign pos2 to pos1 - 1.
I think it's natural, but it's not works when pos1 is 1.

So, my preference is "treat [n,0] as null string if 0 < n".

However, it is no ploblem with the code such as:

local tmp=" $buffer"
region="$tmp[pos1 + 1, pos2 + 1]"

But, I think it's ugly.
Is there exists a more smart code?
# For example, is it representable with only variable expansion?
-- 
Tanaka Akira



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