lua-users home
lua-l archive

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


> However, we do have ipairs, so it'd be nice to have multi-level overrides where it makes sense.
> 
> __next and __index is consistent.
> __pairs and __ipairs is consistent.
> __pairs and __index is not consistent.
> 
> Having the former 2 gives us the best of both worlds.

I raised this a month or two ago, and it was pointed out to me that in some cases the __next method may benefit from having a closure constructed when pairs is first called to assist in future processing, and this argument persuaded me.

Despite the similarity of their names and apparent function, the actual underlying behaviour of `pairs` and `ipairs` can be quite different in complexity.  I prefer to think of `ipairs` as syntactic sugar around a for loop, whereas `pairs` is actually building me a custom iterator closure which it returns as its first result.

Now that I think about it this way I am happy with the current arrangement.

While we're wish-listing, I'd rather that the `__eq` metamethod be observed regardless of the underlying type, and I'd rather that the `__le` metamethod devolve to `l == r or l < r` rather than to `not r < l` since the former works with partial orders whereas the latter requires total orders.  These and a `math.to_integer` rounding function based on C99 `lrintl()` are the only simple modifications I currently run Lua with (I have a more complex strict-upval modification but that changes the parser/compiler, not the runtime).