lua-users home
lua-l archive

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

2015-10-19 0:34 GMT+02:00 Soni L. <>:

> First of all #{} makes no sense, either you know the size
> or you should be using select('#') instead.

If you mean no sane Lua programmer should type that precise
expression, then I agree. If you mean that # acting on any table
constructor makes no sense, then I disagree. As Humpty Dumpty
might have said to Alice: what is #{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}?

> Second it'd be a lot more useful if #... meant the same as
> select('#', ...).
> [skip]
> ...[n] could mean the same as select(n, ...) (but with an opcode
> instead of a function, so that it's slightly faster).

I agree with the spirit of these suggestions. The length operator
has the right feel.

`select` is arguably the least elegant function in the standard library.
There is absolutely no reason why a function call is needed.
The OP_VARARG instruction at present does not use its `C` field.
Those nine bits could be exploited to provide the functionality of

However, there is no need for `...` if we are not calling a function.
The OP_VARARG instruction knows where the vararg is.

The following syntax could be used:

    ##             -- select('#',...)
    #index      -- select(index,...) when n is an integer

All that we would need to sacrifice is the __len metamethod when
its argument is an integer, since then "Lua knows what to do".