Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: string range between 1 and 0.
- X-seq: zsh-workers 7214
- From: Tanaka Akira <akr@xxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxx
- Subject: Re: string range between 1 and 0.
- Date: 20 Jul 1999 14:59:48 +0900
- In-reply-to: "Bart Schaefer"'s message of "Mon, 19 Jul 1999 05:04:57 +0000"
- Mailing-list: contact zsh-workers-help@xxxxxxxxxxxxxx; run by ezmlm
- References: <rsqvhbi7fww.fsf@xxxxxxxxxxxxxxxxx> <990719000259.ZM8741@xxxxxxxxxxxxxxxxxxxxxxx> <rsqbtd9v4eu.fsf@xxxxxxxxxxxxxxxxx> <990719050457.ZM8827@xxxxxxxxxxxxxxxxxxxxxxx>
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