On Wed, Oct 22, 2008 at 05:06:55PM +0200, Tony Mechelynck wrote:
>
> On 22/10/08 16:25, James Vega wrote:
> > On Wed, Oct 22, 2008 at 03:54:23PM +0200, Nikolai Weibull wrote:
> >> On Wed, Oct 22, 2008 at 15:16, Tony Mechelynck
> >> <[EMAIL PROTECTED]> wrote:
> >>
> >>> On 22/10/08 13:57, Nikolai Weibull wrote:
> >>>> [...] I really dislike this tendency
> >>>> computers have to not adhering to the mantra "do as I mean, not as I
> >>>> say".[...]
> >>> Sorry, but in the programming world I don't follow your "don't do as I
> >>> say, do as I mean" mantra. With me it's "do as I say, and if I talk
> >>> nonsense (if I'm using invalid syntax), tell me so".
> >> You miss the point entirely. If I say remove(list, 8, -1) I expect it
> >> to give me a list of the first 8 elements in list.
> >
> > This is odd since, as pointed out earlier, Bram modelled the List usage
> > after Python. remove(list, 8, -1) looks like simple slicing, which
> > would be done as list[:8] in Python and works just fine in Python if the
> > list doesn't actually have 8+ items.
> >
>
> It has everything to do with syntax. The documented syntax (at ":help
> remove()") says if {end} is before {idx} it's an error. The definition
> of a List (see ":help expr-[]") says that element [-1] is the last one
> and that the first element is element [0], therefore I expect
> remove(List,8,-1) to return:
>
> - from the ninth to the last element (inclusive) if there are 9 or more.
> The items returned are removed from the original List.
> - an exception otherwise.
I had glossed over the fact that remove() modifies the list in place
initially. That and the fact that Vim does provide slicing makes
remove()'s behavior more sensical.
:let L = [0, 1, 2]
:echo L[:8]
[0, 1, 2]
The above works just like I (and Nikolai) would expect. That is, it
returns L since L is smaller than 8 items.
> As documented under ":help expr-[:]", List[:8] works in Vim if the
> indices are in range (otherwise it throws an exception). The result is a
> list with the first 9 items removed, if there are at least that many.
Here you mean a list with all items after the 8th index removed.
:let L = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
:echo L[:8]
[0, 1, 2, 3, 4, 5, 6, 7, 8]
--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---