lua-users home
lua-l archive

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


On Wednesday 22 November 2006 8:59 am, Andy Stark wrote:
> Lua list <lua@bazar2.conectiva.com.br> writes:
> >It seems very light to me. The idea is just to add support for
> >multiples values in the [] and do something useful with them.
>
> An alternative to slicing could be to add the sort of functionality that
> array languages have (I mean APL, etc). These languages allow you to use
> an array of integers as a set of indices for another array. In Lua syntax,
> you might have:-
>
>    f = {"apple", "banana", "cherry", "date"}
>
>    result = f[ {2, 4, 3, 4} ]   -- Gives { "banana", "date", "cherry",
> "date"}

not using this syntax i hope, because it would make it impossible to use 
tables as keys.

what's wrong with using a explicit call?

function pick (t,...)
	local out = {}
	for i =1,select ('#',...) do
		out[#out+1] = t[select (i,...)]
	end
	return out
end 

t = {"apple", "banana", "cherry", "date"}
pick (t, 2, 4, 3, 4)  => { "banana", "date", "cherry", "date"}


-- 
Javier

Attachment: pgpPY9gNUsh70.pgp
Description: PGP signature