ID:2645295
 
Not a bug
BYOND Version:513
Operating System:Linux
Web Browser:Chrome 86.0.4240.198
Applies to:DM Language
Status: Not a bug

This is not a bug. It may be an incorrect use of syntax or a limitation in the software. For further discussion on the matter, please consult the BYOND forums.
Descriptive Problem Summary:

Numbered Steps to Reproduce Problem:

Code Snippet (if applicable) to Reproduce Problem:
var/list/LO = list("", "")
var/list/L = list()
L[LO] = list("b"=1)
L.Remove(LO)
LOG << json_encode(L)

Expected Results:
[]

Actual Results:
{"/list":{"b":1}};


var/list/LO = list()
var/list/L = list(LO)
L.Remove(LO)
LOG << json_encode(L)

Expected:
[];

Actual:
[[]];


When does the problem NOT occur?
Only if you won't use lists as keys in dictionary or list
L -= LO
Doesn't work either
Lummox JR resolved issue (Not a bug)
Adding and subtracting two lists, or using Add/Remove which do the same thing, behaves differently than adding/subtracting a single item within a list. This is intended behavior, although I recognize it isn't necessarily always the most convenient. (I'd be open to a feature request for a way to add/remove lists as actual objects instead of as their contents. Not sure what that would look like; it might simply call for two new /list procs.)

The workaround here is to use Find() to find the list object you want to remove from the parent list, and then use Cut() to remove it.

var/list/LO = list("", "")
var/list/L = list()
L[LO] = list("b"=1)
//L.Remove(LO) // since this doesn't work
var/i = L.Find(LO)
if(i) L.Cut(i, i+1)

Although this is obviously not ideal, it's actually not all that different from what DM does internally when you remove an object from a list anyway; it has to look up an index and Cut().

Better practice is to avoid using multi-dimensional lists entirely. It's usually easier to work with something else, like a datum.
I believe you can also do this by wrapping the list to be removed in another list, so:
L.Remove(list(LO))

But this has the drawbacks of being ugly and introducing overhead.
This definitely works for adding but I haven't tested it specifically for removing.
In response to Exxion
Ah yes, wrapping would actually work, but it's definitely an ugly solution.
In response to Lummox JR
Lummox JR wrote:
Adding and subtracting two lists, or using Add/Remove which do the same thing, behaves differently than adding/subtracting a single item within a list. This is intended behavior, although I recognize it isn't necessarily always the most convenient. (I'd be open to a feature request for a way to add/remove lists as actual objects instead of as their contents. Not sure what that would look like; it might simply call for two new /list procs.)

The workaround here is to use Find() to find the list object you want to remove from the parent list, and then use Cut() to remove it.

var/list/LO = list("", "")
> var/list/L = list()
> L[LO] = list("b"=1)
> //L.Remove(LO) // since this doesn't work
> var/i = L.Find(LO)
> if(i) L.Cut(i, i+1)

Although this is obviously not ideal, it's actually not all that different from what DM does internally when you remove an object from a list anyway; it has to look up an index and Cut().

Better practice is to avoid using multi-dimensional lists entirely. It's usually easier to work with something else, like a datum.

Oh, yea, forgot that list1 - list2 will remove from list1 elements in list2... fine...
In response to Exxion
Exxion wrote:
I believe you can also do this by wrapping the list to be removed in another list, so:
> L.Remove(list(LO))
>

But this has the drawbacks of being ugly and introducing overhead.
This definitely works for adding but I haven't tested it specifically for removing.

Thank you too...