lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



On Mar 29, 2011 9:40 AM, "Kristofer Karlsson" <kristofer.karlsson@gmail.com> wrote:
>
> Consider the following simple example:
>
> Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> > function T() return true end
> > function F() return false end
> > mt = {__eq = F, __le = F, __lt = T}
> > t = setmetatable({}, mt)
> > print(t == t, t < t, t <= t)
> true    true    false
>
> t == t gives true even though the __eq would return false, because it always returns true if the operands are the same object.
> t <= t and t < t however, honor the result of __le and __lt.
>
> This seems inconsistent to me.
> t <= t should always give true, by the same reasoning as t == t always is true
> Inversely t < t should always give false.
>
> So, I'd either prefer the same shortcut to be added for __lt and __le, or the shortcut be removed from __eq.
> At the very least, it would be nice with some sort of explanation on why the shortcut for __eq was added in the first place.

Is there any legitimate situation where t == t should be false?