Loading ...
Sorry, an error occurred while loading the content.

40876Re: vim7: changed behavior of split()

Expand Messages
  • A. J. Mechelynck
    Oct 5, 2005
      A. J. Mechelynck wrote:
      > James Vega wrote:
      >> On Wed, Oct 05, 2005 at 08:35:04PM +0200, A. J. Mechelynck wrote:
      >>> Mikolaj Machowski wrote:
      >>>> Hello,
      >>>>
      >>>> Changed behaviour of split(). Try::
      >>>>
      >>>> :echo split("")[0]
      >>>> :echo split("asdf")[0]
      >>>> :echo split("asdf qwer")[0]
      >>>>
      >>>> Is really an empty string such special case it is treated differently
      >>>> than other cases?
      >>>>
      >>>> m.
      >>>>
      >>> I don't see anything wrong:
      >>>
      >>> :echo split("")
      >>> []
      >>> :echo split("asdf")
      >>> ['asdf']
      >>> :echo split("asdf qwer")
      >>> ['adsf', 'qwer']
      >>> :echo split("")[0]
      >>> E684: list index out of range: 0
      >>> E15: invalid expression: split("")[0]
      >>> :echo split("asdf")[0]
      >>> asdf
      >>> :echo split("asdf qwer")[0]
      >>> asdf
      >>>
      >>> Explanation:
      >>>
      >>> - split("") is the empty list, it has no element. It's first element
      >>> (element 0) doesn't exist.
      >> I think Mikolaj was suggesting that split("") should return [""],
      >> similar to how split("asdf") returns ["asdf"].
      >>
      >> James
      >> --
      >> GPG Key: 1024D/61326D40 2003-09-02 James Vega <jamessan@...>
      >
      > split("") returns a list of zero elements
      > split("asdf") returns a list of one element
      > split("asdf qwer") returns a list of two elements
      > split("asdf qwer uiop") returns a list of three elements
      > split("asdf qwer uiop hjkl") returns a list of four elements
      > etc.
      >
      > Returning a list of one empty element, rather than zero element, _that_
      > would be "special" and "abnormal" handling. Or else split() should
      > return an additional empty element at the end of the list in all cases,
      > but there is no need for that since we can test l(list).
      >
      > If you want to avoid errors at all costs without testing l(list), read
      > the help text I mentioned in the text you snipped (":help E684") which
      > mentions the get() function.
      >
      > Best regards,
      > Tony.
      >
      >
      >
      >

      Oops

      :s/l(list)/len(list)/g

      Tony.
    • Show all 8 messages in this topic