[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Next Lua (5.2) feature request : slicing
- From: "Andy Stark" <AStark@...>
- Date: Wed, 22 Nov 2006 13:59:30 GMT
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"}
You also have a function that generates an array of integers from 1 to n
(for some reason, this function is usually called "iota"):-
result = f[ iota(2) ] -- Gives {"apple", "banana"}
...and you can imagine functions to generate a range from m to n, reverse
an array, etc. When used in combination, they are very expressive and tend
to reduce the number of explicit loops required in the code.
This kind of functionality should be relatively simple to implement either
in pure Lua or in the standard libraries in C and wouldn't require any
extra opcodes. It would be nice to have as a built-in feature of standard
Lua but perhaps it wouldn't get enough usage to justify that.
&.
#####################################################################################
This e-mail message has been scanned for Viruses and Content and cleared
by MailMarshal.
The Blackpool Sixth Form College.
#####################################################################################