lua-users home
lua-l archive

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


Lua list <lua@bazar2.conectiva.com.br> writes:


>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,...)

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

Ahem... yes, you're right - I forgot that the operation of using a table
as a key was already defined by default.

There's nothing wrong in principle with using a function to index a table
in this way but it must be possible to pass this function a table rather
than just a variable length argument list. A table can be generated at
runtime whereas an argument list is fixed in the source code.

Another approach to multiple indices might be to define the function call
operator ( ... ) for tables so that the values passed are treated as
subscripts. Slices could be modelled using a pair of integer arguments:-

   t = {"apple", "banana", "cherry", "date"}
   x = t( 1, 2)  -- Gives { "apple", "banana" }

...and when the argument is a table, it could give the APL-style array
indexing behaviour we have been discussing:-

   firstAndLast = { 1, 4 }
   x = t( firstAndLast )

...and then of course we would also have:-

   x = t{ 1, 4 }

&.



#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared 
by MailMarshal.
The Blackpool Sixth Form College.
#####################################################################################