lua-users home
lua-l archive

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


2014-04-10 8:49 GMT+02:00 steve donovan <steve.j.donovan@gmail.com>:

> On Thu, Apr 10, 2014 at 8:41 AM, Dirk Laurie <dirk.laurie@gmail.com> wrote:
>> Suppose that the notation tbl[i,j,k] meant tbl[i],tbl[j],tbl[k], not
>> as a syntactic sugar, but as genuine multiple indexing overridable
>> by metamethods.
>
> It's a cool idea - I should say, it's still a cool idea since there
> has been at least one thread about it before:
>
> http://lua-users.org/lists/lua-l/2010-10/msg00761.html
>
> People were rather concerned about efficiency at the time - you do not
> want to slow the language down for an occaisional convenience

Implementation would have very little more overhead than at present:
a simple check on lua_top for the number of arguments.

> Also, it makes particular sense when overridden by extended
> metamethods, but what precisely does it mean in their absence?  That
> tbl[i,j] is tbl[i][j]?  That's what I would expect from my old Fortran
> days....

No, it means just what I said at the beginning. Term-by-term indexing.
Vararg maps to variable return list. In effect a fallback metamethod
if you have failed to provide one yourself.

For tbl[i,j] to mean matrix indexing requires extra information, and therefore
a metamethod — but at present such metamethod can't use that syntax.

Let's not get onto the topic of Fortran. I'm even more of a Fortran apostate
than a Python apostate.