[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Inconsistency in __eq, __lt, __le
- From: Kristofer Karlsson <kristofer.karlsson@...>
- Date: Tue, 29 Mar 2011 16:40:04 +0200
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.
/Kristofer
- Follow-Ups:
- Re: Inconsistency in __eq, __lt, __le, Rebel Neurofog
- Re: Inconsistency in __eq, __lt, __le, liam mail
- Re: Inconsistency in __eq, __lt, __le, Paul Bonser
- Re: Inconsistency in __eq, __lt, __le, Dimiter "malkia" Stanev