ID:891912
 
Keywords: index, list, python
Applies to:Dream Maker
Status: Open

Issue hasn't been assigned a status value.
It would be amazing if we could use negative indices in lists. Similar to the recent feature of negative values in text functions.

I believe this would allow for cleaner code when working with lists. To get the last element of a list we could do:
world << list[-1]

Instead of:
world << list[list.len]


It would also be great if we could extend this to list features similar to the slices used in Python. For example:

var/list/L = list(1,2,3,4,5,6,7,8)

//If we want the forth element onward we have to do:
L.copy(4,0)

//With new notation we could do:
L[4:0]


An optional third element could also be added as the stride:

L[::2] //Returns every other element
L[2:5:2] //Every other element from 2 to 5
L[::-1] //Reverses a list




I support increased list functions.
This functionality would be a great addition, matching the text function feature. I'm surprised I didn't request this side-by-side with my feature request.
DM has chosen to do things via procedures attached to the special /list object; altering that now is a bit of a stretch, and if you were to do that you'd want it to be a replacement of Copy() etc, not an addition.

The only thing not actually possible already through the existing list procedures / for-loop skip, is the list reversing. I wouldn't mind list.Reverse, although its fairly trivial to implement given list.Swap. In fact, Swap was primarily implemented to support user-created sorting routines, such as a reversal.
It would be awesome if we could override list procs or add new ones, like a sorting function. Right now it's not allowed ;_;
IMO BYOND should allow lists to somehow end up in C/C++ libraries so you can pass them through a call() request, and potentially get them as return values too.

That way, it becomes even easier to write list sorting functions in C/C++ and use those in BYOND. Right now you'd have to mess around with text and have BYOND->C/C++ mutually agree on a "separator" character to use.
In response to JBoer
JBoer wrote:
IMO BYOND should allow lists to somehow end up in C/C++ libraries so you can pass them through a call() request, and potentially get them as return values too.

That way, it becomes even easier to write list sorting functions in C/C++ and use those in BYOND. Right now you'd have to mess around with text and have BYOND->C/C++ mutually agree on a "separator" character to use.

You could just send/return the string in the same format list2params() and params2list() use.
Good idea! I never thought of that. Thanks!
I just wanna paste this old topic mentioning similar things.
id:132730
In response to ExPixel
That's actually how my DMI Icon Info library passes data back and forth. It works surprisingly well. You can even nest lists within lists within lists.