On Sun, Sep 7, 2008 at 6:33 PM, Matt Wozniski <[EMAIL PROTECTED]> wrote:

>
> Using ==, strings and numbers can compare as equal, and using index()
> on a list, this is not the case:
>
> :echo "2" == 2            " Returns 1
> :echo index( [ 2 ], "2")  " Returns -1
>
> The docs just say that index() will "Return the lowest index in |List|
> {list} where the item has a value equal to {expr}", leading one to
> assume that equality is checked in the same way as ==, but looking at
> the source, we're using a function that "Compares the items just like
> "==" would compare them, but strings and numbers are different".  So,
> is this a behavioral bug, or should the help just make a note that
> strings and numbers will not be considered equal?


 I've noticed that the equality function being used by index is the same one
as used when comparing lists and dicts for equality - meaning that the lists
[1, 2, 3] and ['1', '2', '3'] will not compare equal, either.

But the help item for expr-== says that strings are converted to numbers
before comparison.  It doesn't mention this special case when the strings
and numbers happen to be elements of collections.

I think that converting all strings into numbers for such comparisons makes
the most sense because it makes the language more regular.  If we merely
document this exception to the rule, we'll just create extra trouble for
scriptwriters.

>
>
> ~Matt
>
> >
>
Erik

-- 
Erik Falor
Registered Linux User #445632 http://counter.li.org

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui