ID:2028902
 
Applies to:DM Language
Status: Open

Issue hasn't been assigned a status value.
We have the | and + operators for two different forms of list combination, but the only deletion operator removes one at a time.
var/list/a = list(1, 2, 3, 4) + list(2, 4) // (1,2,3,4,2,4)
var/list/b = list(1, 2, 3) | list(2, 4) // (1,2,3,4)

var/list/c = a - 4 // (1,2,3,4,2)
var/list/d = b - 4 // (1,2,3)



I submit that a builtin operator or list/proc such as the following may belong.
/proc/conclusively_remove(var/list/l, var/s)
. = l.Copy()
while(s in .)
. -= s
Can't the ^ operator do this?

list("hi", "bye", "hi", "bye", "hi", "bye") ^= list("hi")
In response to Super Saiyan X
Super Saiyan X wrote:
Can't the ^ operator do this?

list("hi", "bye", "hi", "bye", "hi", "bye") ^= list("hi")

Result is list("hi", "bye", "hi", "bye", "bye"), so no.
var/list/a = list(1,2,3,4)
var/list/b = list(3,4,5)


var/list/c = a^b //list(1,2,5)


var/list/d = c&a //list(1,2)


Full operation would be:

a&(a^b)
The documentation for A^B makes it sound like all matches in A for any items in B would be removed, hm.
^ is equivalent to the XOR operation, so it carries the risk of injecting new entries from the right-hand list.

Even so, I can't get around needing to iterate, since ^ and & will not obtain more than the minimum number of instances from both lists.

    a = list(1,2,3,4,5,2,3,4,5)
b = a - 4
c = a ^ (a & 4)

world << "a [list2str(a)]"
world << "b [list2str(b)]"
world << "c [list2str(c)]"

c = c ^ (c & 4)
world << "c [list2str(c)]"
c = c ^ (c & 4)
world << "c [list2str(c)]"


a (1 2 3 4 5 2 3 4 5 )
b (1 2 3 4 5 2 3 5 )
c (1 2 3 4 5 2 3 5 )
c (1 2 3 5 2 3 5 )
c (1 2 3 5 2 3 5 )
In response to Ter13
Ter13 wrote:
> var/list/a = list(1,2,3,4)
> var/list/b = list(3,4,5)
>


> var/list/c = a^b //list(1,2,5)
>


> var/list/d = c&a //list(1,2)
>


Full operation would be:

> a&(a^b)
>

a = list(1,2,3,4,4,4);
b = list(3,4);

a&(a^b): list(1,2,4,4).
Most languages do include a removeAll() function. An operator would be nonsense because it's not part of the standard programming lexicon.

Though, a removeAll() is as simple as:

proc/list_remove_all(list/l,list/removing)
var/list/r = removing&l
while(r.len)
l -= r
r = r&l


Although, the most performant solution would probably look quite a bit different.
I'm pretty sure Lummox gave this as a solution before, when he deferred another topic with a slightly similar request:

while(list.Remove(item));


Obviously, might be a bit heavier than a pure operator solution.

but also, http://www.byond.com/forum/?post=259499 (lol)
In response to Super Saiyan X
Super Saiyan X wrote:
while(list.Remove(item));

And I thought I was getting fancy using . .