[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
**Subject**: **Re: Inconsistency in __eq, __lt, __le**
**From**: Henk Boom <henk@...>
**Date**: Wed, 30 Mar 2011 14:49:22 -0400

On 30 March 2011 14:34, Paul Bonser <misterpib@gmail.com> wrote:
>
> 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?
>From another thread:
> t = 0/0
> return t == t
false