lua-users home
lua-l archive

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




On Thu, May 21, 2020 at 12:31 PM Coda Highland <chighland@gmail.com> wrote:


On Thu, May 21, 2020 at 12:26 PM Andrew Gierth <andrew@tao11.riddles.org.uk> wrote:
>>>>> "Coda" == Coda Highland <chighland@gmail.com> writes:

 >> why the _ipairs metamethod was deprecated?

 Coda> Because there's no need for a metamethod for something as simple
 Coda> as ipairs()

Some of us greatly disagree with this position - in particular, it
seriously impacts what you can do with userdatas.

For example, if embedding into an environment (e.g. a database) which
has a native array type (such as SQL arrays) which can be iterated
sequentially more efficiently than they can be indexed into (because
they have variable-length elements), it means that you can't just
provide an __ipairs and have everything just work in the obvious way;
instead, ipairs() will work inefficiently and you have to provide a new
but functionally identical method.

IIRC the whole reason that ipairs doesn't need a dedicated metamethod is because there's ALREADY a metamethod for it: __len. If "for i = 1, #ud" works then "for k, v in ipairs(ud)" ought to work, I thought.

/s/ Adam

Oh hold on, never mind. I understand a bit better now -- I misread what you had written, my apologies.

I disagree that it's functionally identical, though. It changes the state of the container, whereas ipairs() doesn't. I really see no reason to complain about "for k, v in result:rows()".

/s/ Adam