ID:30683
 
While debugging a new feature to my pathfinder library I ran into an annoying problem. When using list.Add() and passing in a list it merges them and the same thing happens when using the + operator(which after reviewing the reference happens to be intended :P) this behaviour however is very annoying if you don't want a combined list rather a list of lists. Or in my case a list of seperate paths. Anyway if anyone else is trying this my solution to forcing the add rather than merging is this

var/L[] = new()
var/L2[] = list(1,2,3)
var/L3[] = list(4,5,6)

L[++L.len] = L2
L[++L.len] = L3

Which will result in L containing 2 seperate lists rather than one merged one if add were used. This feels a bit ad hoc so if anyone has a cleaner solution please comment :P.
Continuing with your example with those example vars:

var/L[] = new()
var/L2[] = list(1,2,3)
var/L3[] = list(4,5,6)

L += list(L2, L3)

would also work.
That seemed like it would be a bit goofy. But nope that doesn't work. It appends both lists to L and makes a list of 6 numbers rather than a list of 2 lists.
Can't you do something like:
var/L[][] = new()
var/L2[] = list(1,2,3)
var/L3[] = list(4,5,6)
for (var/i = 1; i<L2.len; i++)
L[1][i] = L2[i]

Or something to that effect.
Not sure. Always thought multi-dimensional lists had to be fixed length. However I simply want a list of lists. The nested lists may be of different sizes.
I don't think so. I think multi-dimensional lists are still dynamic (don't quote me on this).
You could always just make a function that takes a multi-dimensional list and a regular one and you add them together yourself.
This kind of seems like a hacky way to do it though. There must be an easier way. I just can't seem to think of one right now.
Sorry.
Why don't you have a list of datums that point to lists?
That works however it adds more overhead to making the list of lists and adds work to iterating over the results. And in the end feels more ad hoc than my solution :P.
I expect this happens because DM is very generous about syntax.

If its a large issue for you to work with things that way, design around it ;)

proc/AppendLists(list/L)
var/arglen = length(args)
if(arglen < 2) return 0
for(var/i = 2, i <= arglen, i++)
L[++L.len] = args[i]


All things aside, I do agree that its slightly confusing; I don't particularly see a solution to it though, since DM is keeping with its syntax by treating your example like it does. It strikes me that it'd be nice to be able to add procedures to lists (like sorting routines, or the above procedure).
Audeuro wrote:
var/L[] = new()
var/L2[] = list(1,2,3)
var/L3[] = list(4,5,6)

L += list(L2, L3)

would also work.

world << L.len
for(var/X in L)
world << X

Output:
2
/list
/list

Is that not what you wanted? :p
Ahh whoops I did L.Add(L2,L3) in my test case for some reason not L += list(L2,L3) :P. I guess merging only unwraps one layer and doesn't recursively unwrap lists when merging then.