lua-users home
lua-l archive

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


Ignacio Burgueño <ignaciob@inconcertcc.com> writes:

> For me, __len has clear semantics. The length of something is
> measurable in 'n' units, with 'n' being a number.

Disagree.  If I implement a table "naturals" with iterators that will
never stop, I can make __len return a specific value aleph0 that is not
a number.

> Using __len for other uses seems like a case of operator overloading
> abuse (C++).
>
> Even the common idiom of "t[#t + 1] = something" will have to take
> care of checking the type of #t before doing arithmetic with it.

If t is supposed to represent the naturals, the "common idiom" should
indeed bomb out.

Virtualizing tables via metatables offers some possibilities where it
does not make sense to artificially add restrictions that serve no
purpose except adding restrictions.  Complicating the language in order
to be able to do less with it is a bad deal.

I remember being hit by C++' operators only being allowed to be
non-static member functions.  The answer of Stroustroup about that
restriction was basically "nobody would need static member functions as
operators anyway".  Which was obviously not the case for the application
I had in mind.

A restriction that is only there in order to incur penalties for program
and programmer, without inherent necessity, is one I can do without.

-- 
David Kastrup