lua-users home
lua-l archive

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



luaSub has a syntax mod exactly like your proposal (used by 'luas - sselect'):

--
-- SELECT syntax mod                   Copyright 2006-08 Asko Kauppi
--
-- Simplifies the 'select' usage a bit, making it look less like a function
--
--    #...    ->  select('#',...)   number of values in ...
--    ...[n]  ->  (select(n,...))   value #n of ...
--
-- Note: 'select(n,...)' is still used explicitly when wanting all values-- from 'n' onwards.
--


Alex Davies kirjoitti 9.4.2008 kello 9:38:
Hey all,

Just wondered if the following syntax is being considered at all:

 for i = 1, #... do
   print(...[i])
 end

Imo it seems a natural extension, and less cumbersome then:

 local select = select
 for i = 1, select("#", ...) do
   print(select(i, ...))
 end

And would of course be orders of magnitude faster for large varargs.

It would also allow writing select in pure lua, something which is currently impossible. Still, I can see that some people may not like the syntax, just wanted to throw it out
there anyway.

- Alex

P.S. I do realise it's a little inconsistent, as true lists will never be indexable... eg:
 local a = (1, 2, 3)[3]