zsh-workers
 help / color / mirror / code / Atom feed
From: "Bart Schaefer" <schaefer@candle.brasslantern.com>
To: Tanaka Akira <akr@jaist.ac.jp>, zsh-workers@sunsite.auc.dk
Subject: Re: string range between 1 and 0.
Date: Mon, 19 Jul 1999 00:02:59 +0000	[thread overview]
Message-ID: <990719000259.ZM8741@candle.brasslantern.com> (raw)
In-Reply-To: <rsqvhbi7fww.fsf@crane.jaist.ac.jp>

On Jul 18,  1:14pm, Tanaka Akira wrote:
} Subject: string range between 1 and 0.
}
} Hi. I wondered that $var[1,0] is expanded to first character of v.
[...]
} Is this intentional behaviour?

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

For quite some time now, it has been the case that $x[0] == $x[1] when
NOT emulating ksh.  This documented in section 2.1 of the FAQ, though it
does not seem to be mentioned in the actual manual.

The same code is used to interpret the second value in a subscript range,
so $x[0,0] == $x[1,1] == $x[0,1] == $x[1,0] unless you are using zero-
based arrays as in ksh.  This also means that $x[2,0] == $x[2,1] which is
the empty string either way; the only interesting thing happens when the
first of the range is 1.

} I think that $v[1,0] should be null string as $v[2,0].

It is, when ksharrays is set ...

If it weren't handled this way, then $x[anything,0] in the non-ksharrays
case would have to yield an "invalid subscript" error -- the only other
alternative is to treat $x[n,0] as $x[n,-1] which gives all the elements
from n to the end.

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

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com


  reply	other threads:[~1999-07-19  0:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-07-18  4:14 Tanaka Akira
1999-07-19  0:02 ` Bart Schaefer [this message]
1999-07-19  1:01   ` Tanaka Akira
1999-07-19  5:04     ` Bart Schaefer
1999-07-19 19:10       ` Wayne Davison
1999-07-20  5:59       ` Tanaka Akira

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=990719000259.ZM8741@candle.brasslantern.com \
    --to=schaefer@candle.brasslantern.com \
    --cc=akr@jaist.ac.jp \
    --cc=zsh-workers@sunsite.auc.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).