lua-users home
lua-l archive

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


on 9/12/06 3:29 AM, David Jones at drj@pobox.com wrote:

> I'm always very loath to suggest or support more syntax, but how
> about if '#' on its on in an expression inside [] were to mean the
> length of the table being indexed.  So you could go:
> 
> t[#+1] = value
> 
> It's pretty clear, and almost syntactically unambiguous.

I was about to make the same suggestion.

Speed is an issue, but I think this really comes down to the fact that if
table.insert is to be deprecated, then it would be nice if it's replacement
were friendly to names longer than one character. As noted elsewhere, if
speed is absolutely critical, you do something like:

    local count = #myArrayWithTheLongName

    for v in generateValues() do
        count = count + 1
        myArrayWithTheLongName[ count ] = v
    end

But while we're worrying about the fate of table.insert, what if it regained
its status as a way to insert into tables but was rewritten to look for an
__insert metamethod?

Mark