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

Re: "It would be nice" (Was: patch: ':let a="+10"' etc)

Expand Messages
  • Neil Bird
    ... In that case, it can come down to: which interpretation do people (read: Bram) prefer? I think I d vote for the new way, but I can see how correctly
    Message 1 of 7 , Feb 2, 2001
    • 0 Attachment
      Benji Fisher wrote:
      > Until vim 6.0, strpart("abc", -1) was illegal, as was
      > strpart("abc",1). Thus the compatibility issue is not too great: how
      > many scripts have been written since 6.0 alphas started coming out that
      > rely on strpart("abc",-1) returning "abc"?

      In that case, it can come down to: which interpretation do people (read:
      Bram) prefer? I think I'd vote for the 'new' way, but I can see how
      'correctly' interpreting negative start indices would be useful in scripts
      (to catch boundary cases).

      Unless, of course, another combination can be thought of. Negative
      lengths?

      --
      =====================- http://www.thalesgroup.com/ -=====================
      Neil Bird | If this .signature |
      work mailto:neil.bird@... | looks pants, then | $> cd /pub
      personal mailto:neil@... | stop using Outlook! | $> more beer
    • Bram Moolenaar
      ... I like that better than a negative argument. If the offset argument is a variable, and it accidentally becomes negative (e.g., -1), you don t suddenly
      Message 2 of 7 , Feb 2, 2001
      • 0 Attachment
        Michael Geddes wrote:

        > I think a new function is in order.
        >
        > strpartright("abc",1)
        > would return 'ab'
        > strpartright("abc",0,1)
        > would return 'c'

        I like that better than a negative argument. If the "offset" argument is a
        variable, and it accidentally becomes negative (e.g., -1), you don't suddenly
        want to get characters from the other side of the string.

        > I also think that a better 'modification' to strpart using -ve values would
        > be:
        >
        > strpart( {strexpr}, {start}, -{len} )
        > equivalent to
        > strpart( {strexpr}, {start}, strlen({strexpr}) - {len} )
        >
        > so
        >
        > let a = "'my string'"
        > echo strpart( a, 1,-1)
        >
        > would echo:
        > my string

        That makes sense. Although I think the example should be:

        echo strpart(a, 1, -2)

        You're taking off two characters, one on both sides.

        However, the when the length is computed, and you accidentally end up
        computing a negative length, you don't get what you want.

        I don't like the idea of a negative value making the function do something
        different. The meaning of the function call becomes less obvious, you have to
        look carefully to see what it does. So, let's just use that strlen()
        explicit, that's much clearer.

        For all these theoretical items, it's very useful to see some actual code that
        uses it. Only then can we find out what is easy to use and what isn't.

        --
        hundred-and-one symptoms of being an internet addict:
        120. You ask a friend, "What's that big shiny thing?" He says, "It's the sun."

        /// Bram Moolenaar -- Bram@... -- http://www.moolenaar.net \\\
        ((( Creator of Vim - http://www.vim.org -- ftp://ftp.vim.org/pub/vim )))
        \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///
      Your message has been successfully submitted and would be delivered to recipients shortly.