lua-users home
lua-l archive

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


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Doug Rogers wrote:
| On Friday 20 August 2004 09:55, Roberto Ierusalimschy wrote:
|
|>>skip(i, ...)    -->     slice(i, ...)
|>>first(...)      -->     slice(1, 1, ...)
|
|>How would you know whether the second "1" is a counter or the first
|>value from `...´?
|
| Couldn't the compiler/interpreter put the proper backend in for this?
|
| Maybe I'm missing something here. Are the dots above literals meant to
| represent what is currently called 'arg', or do you intend to be able
to use
| 'slice()' for things such as:
|
|   > print(slice(1, 2, 3, 4, 5))
|   3       4
|
| Either name slice() or select() works. But I like Michael Roth's
all-in-one
| version to handle first, last, etc.

Maybe the easist would be that the slice() needs always the start end
end position. Then you have to write -1 as the end:

select(i, ...)	-->	slice(i, i, ...)
skip(i, ...)	-->	slice(i, -1, ...)
first(...)	-->	slice(1, 1, ...)
first(i, ...)	-->	slice(1, i, ...)
tail(...)	-->	slice(2, -1, ...)
last(...)	-->	slice(-1, -1, ...)
last(i, ...)	-->	slice(-i, -1, ...)

and so on. In the case of index overflows an empty list should returned.


Michael Roth




-----BEGIN PGP SIGNATURE-----
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFBJkb0SIrOxc3jOmoRAqziAKCUwLJE8oHZdRYJYvksDuKcjHJznACgt7OK
18n/qf9ef6slunAxBKXI6Dc=
=6tWX
-----END PGP SIGNATURE-----