[prev in list] [next in list] [prev in thread] [next in thread] 

List:       vim-dev
Subject:    RE: lists - inclusive vs exclusive
From:       "Halim, Salman" <salman () hp ! com>
Date:       2005-01-21 14:37:51
Message-ID: B11A8088B27BA84B821319DBE2DA76CD070EAB4D () tayexc17 ! americas ! cpqcorp ! net
[Download RAW message or body]

I've seen this sort of thing done in two ways across different
platforms, languages etc.:

- list[a:b] where a is the start index and b is the number of items, so
list[2:3] returns the items at 2, 3 and 4 (3 items starting from index
2).
- list[a:b] where a is the start index and b is the end index -- this is
*usually* inclusive, I believe.  However, I see the point of making it
exclusive in that you could pass in the total size of the list as the
second parameter (which is 1 more than the index of the last item in a
0-based list), but I think Vim 7 allows for that by simply doing
something like list[a:], so I'm in favour of letting it be inclusive.

Cheers,

Salman.

> -----Original Message-----
> From: Ilya Sher [mailto:ilya-vim@actcom.net.il] 
> Sent: Friday, January 21, 2005 3:31 AM
> To: vim-dev@vim.org
> Subject: Re: lists - inclusive vs exclusive
> 
> On 2005-01-20 15:32, Keith Roberts wrote:
> > >-----Original Message-----
> > >From: Ilya Sher [mailto:ilya-vim@actcom.net.il]
> > >Sent: Monday, January 17, 2005 11:33 AM
> > >To: vim-dev@vim.org
> > >Subject: lists - inclusive vs exclusive (was: Re: New Vim 7
> > >feature: Lists)
> > >
> > >On 2005-01-14 12:30, Bram Moolenaar wrote:
> > >> Nobody made a remark about the last index being inclusive, while 
> > >> Python does this exclusive.  Does this mean people think being 
> > >> inclusive is more logical?  That's the reason I did it that way.
> > >
> > >+1 for exclusive.
> > >list[a:b] should have the length of (b-a) elements, not (b-a)+1.
> > >
> > >Just my 2 agoras.
> > 
> > Umm.  IIUC,
> > 
> > Case 1.  Exclusive, read "a to b", would include elements: a ... up 
> > to, but not including, b.  #elements = b-a
> > 
> > Case 2.  Inclusive, read "a thru b", would include 
> elements: a ... b.
> > #elements = b-a+1
> > 
> > -Keith
> Yes, that's what I meant.
> 
> --
> PGP k: 3A4A  810C  1C81  79F3  A8C6  2545  90FD  6114  F730  0680
> Rules: *NIX, UTF-8, Lisp, S-exps, FP, Encryption, OSS, VIM, Gnome
> Sucks: M$,  XML,  Bad Code,  Morons on the Web,  toy text 
> editors Social Engineering - Because theres no patch for 
> human stupidity.
> 

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic