V: consider having 'map = { }' to clear a map

Created on 22 Jul 2020  路  1Comment  路  Source: vlang/v

We have a = [ ] to clear an array. It's very natural to also have a = { } to clear a map.

fn main() {
    mut a := {'one':1}
    a = {}
}

Now the above code, for example, gives V error - type map_string_int is private.

Bug

Most helpful comment

Be careful, a = [] doesn't clear the array, it creates a new one (and therefore requires a new memory allocation). a.clear() really removes the items from the array.

This isn't really a feature request, and more a bug report, it should already work.

>All comments

Be careful, a = [] doesn't clear the array, it creates a new one (and therefore requires a new memory allocation). a.clear() really removes the items from the array.

This isn't really a feature request, and more a bug report, it should already work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PavelVozenilek picture PavelVozenilek  路  3Comments

elimisteve picture elimisteve  路  3Comments

ArcDrake picture ArcDrake  路  3Comments

aurora picture aurora  路  3Comments

jtkirkpatrick picture jtkirkpatrick  路  3Comments