lua-users home
lua-l archive

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



On 30 Aug 2007, at 13:47, David Kastrup wrote:

David Jones <drj@pobox.com> writes:

On 30 Aug 2007, at 12:47, David Kastrup wrote:


On a different tack: maybe one could optimize usage like

   for i=1,#{...} do something(({...})[i])

to not actually create tables in order not to have to use select at
all?  That would make for more consistency in a different area.
Incidentally, {...}[i] is not allowed.

A slight aside: you do realise that #{...} and select('#', ...) don't
have quite the same meaning?

The select function's description and use in "Programming in Lua" is
not really elaborate enough to get the fine points.  The "Reference
Manual" at least makes it obvious that select returns multiple values
when given a numeric first argument.

The connection with the arg array (in particular with arg[0],
arg[-1]...) outside of any function also is not really documented
exhaustively in either tome.

So I certainly have to plead guilty to most "you do realise" kinds of
question.

I think I assumed you did know deep down that they were different but just needed reminding.

I was thinking of the difference when the argument list has nils in it. #{...} won't count trailing nils and will do even more bizarre things for interior nils.

select('#',...) is the right one. It does seem a bit long-winded when all wanted to know was the number of arguments.

One of the problems is that most of the plausible alternate syntaxes already have meanings in Lua 5.1. Obscure and not very useful meanings usually.

drj