[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Next Lua (5.2) feature request : slicing
- From: Mildred <ml.mildred593@...>
- Date: Wed, 22 Nov 2006 00:22:40 +0100
Le mar 21/11/2006 à 23:53 Mike Pall à écrit:
> Hi,
>
> Mildred wrote:
> > Why do not add slicing in the next release of Lua ?
> > [...]
> > Any toughts about it ?
>
> http://lua-users.org/lists/lua-l/2004-11/msg00083.html
>
> Bye,
> Mike
>
Maybe it is possible without adding new opcodes.
IO was just thinking that actually, the [] syntax accept only one value
and that it could be possible to put multiples values in there. And
then, the default behaviour would be :
- for tables to extract a part of it
- if the __index metamethod is defined, just give the multiples
values as parameter
Ahd the tab[x:y] syntax would simply be syntaxic shugar for tab[x,y].
It seems very light to me. The idea is just to add support for
multiples values in the [] and do something useful with them. But I
don't know lua internals, so maybe it is not. But I think, if it is
easy to do, why not have it ?
Also, in my post, there was something else, indexing strings by default
(change metatable). To be able to do ("abc")[2].
Speaking about strings, I think slicing is much more useful with string
than with tables, so it is a good idea to have it. You can see that
we have a string.sub but no table.sub function :)
The problem with that solution is that slicing assigment is not
possible. Something like a[1:3]=b[2:4], but I don't think it is very
used. And it is still better to have basic slicing than nothing.
--
Mildred <xmpp:mildred@jabber.fr> <http://mildred632.free.fr/>
Clef GPG : <hkp://pgp.mit.edu> ou <http://mildred632.free.fr/gpg_key>
Fingerprint : 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 [9A7D 2E2B]