lua-users home
lua-l archive

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

2011/5/2 steve donovan <>:
> On Mon, May 2, 2011 at 10:32 AM, Benoit Germain <> wrote:
>> #... is a faux-ami, much better understood as
>> local a = ...
>> local n = #a
> There are two dimensions to any change in a language; efficiency and elegance.
> This patch optimizes a rather particular case; unless select(i,...)
> were similarly optimized, then I doubt that the even most sensitive of
> tests would detect any difference. Mostly, we just use table.pack(...)
> which is pretty fast, and would be faster than having to resort to
> select(i,...) anyway.

Which is why I propose ...[n] as well (though I haven't implemented
it). But I aknowledge the difficulty posed by the fact that ... is an
expression and not a variable.

> Elegance:  I think #... pretends that ... is a variable, which it is
> not. It is shorthand for a number of unnamed parameters and
> semantically behaves just like 'a1,a2,a3' etc.

There is another way of seeing it:
#... pretends it is a single token evaluating to the number or
received arguments, but that can be written as # ... as a convenience
for those who prefer to separate '#' and '...' for readability. I
could as easily have coded the patch as a new token '#...', where #...
is the number of received arguments, and the significance of # ... is
unchanged, as the length of the first item in ... . But this opens a
door for hard-to-find bugs where a single whitespace changes the
meaning of the expression, which is utterly un-Lua.