similarly you also have:

#> compare(0, '')
==> 0

#> compare(0, [])
==> 0

.. But, equivalence is one thing, defining "meaningful" ordering is
more difficult.

A quick take in Python gives this table (didn't check the standard):
----------
>>> '' == []
False
>>> '' < []
False
>>> '' > []
True
>>> 0 < ''
True
>>> 0 > ''
False
>>> 0 < []
True
>>> 0 > []
False
----------------

At least the above defines an ordering, where JavaScript returns false
for any ordering of 0, [] and ''" for example.
More thoughts?

Regards
// Fredrik

On Oct 28, 7:00 am, Per Cederberg <[email protected]> wrote:
> While writing some MochiKit tests, I stumbled upon the following:
>
> #> compare("", [])
>   ==> 0
>
> #> "" == []
>   ==> true
>
> Seems like the JavaScript type coercion is used inside compare():
>
>     compare: function (a, b) {
>         if (a == b) {
>             return 0;
>         }
>         ...
>
> But perhaps that was just a mistake? It seems to be at odds with the
> idea of a "safe" compare function... If nobody is terribly dependent
> on this I'll fix it for 1.5. But please verify this if you are
> extensive users of compare().
>
> Cheers,
>
> /Per

-- 
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en.

Reply via email to