Srinath Avadhanula wrote:

> I am wondering if its just me who feels that the restrictions placed on
> some of the List functions are not such a great idea.
> 
> 1. a[:5] in python returns the first five elements of a if len(a) > 5 or
> all elements if len(a) < 5. In VimL, a[:4] is an error if len(a) < 5. Right
> now, we have to do something like: a[:(min(5,len(a))-1)] to get the same
> behavior. It seems to be a common enough behavior to want to get the first
> so many elements (or less) of a list that I have found myself doing this at
> least 5-6 times already... Python seems to have gotten this right IMHO.

I suppose this means that when the second index is higher than the
length of the list it's set to the length of the list.  It also means
that you will never get an error message when the list is shorter as you
expected.

What do others think?

> 2. In VimL, a[N:M] is an error if M<N-1 (alghough its not when M=N-1!).
> In Python, this is just an empty list. This too has to be accounted for
> using verbose min() statements. What is the motivation for this
> restriction? Is it an implementation issue?

If you have M smaller then N minus one you have probably done something
wrong.

> In fact, why not model VimL's lists on Python's lists?

In Python many errors go unnoticed.  I learned that the hard way.  This
is a balance between having the language warn you about errors, or
letting it up to the user to discover why something doesn't work.
For Python they might have a different idea about the right way, but
they can't change it without breaking existing scripts.

-- 
"Thou shalt not follow the Null Pointer, for at its end Chaos and
Madness lie."

 /// Bram Moolenaar -- [EMAIL PROTECTED] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\        download, build and distribute -- http://www.A-A-P.org        ///
 \\\            help me help AIDS victims -- http://www.ICCF.nl         ///

Reply via email to