compiler: implement clear builtin for maps

This commit is contained in:
Ayke van Laethem
2023-07-07 15:47:49 +02:00
committed by Ron Evans
parent a2f886a67a
commit f1e25a18d2
7 changed files with 64 additions and 0 deletions
+11
View File
@@ -15,4 +15,15 @@ func main() {
s := []int{1, 2, 3, 4, 5}
clear(s[:3])
println("cleared s[:3]:", s[0], s[1], s[2], s[3], s[4])
// The clear builtin, for maps.
m := map[int]string{
1: "one",
2: "two",
3: "three",
}
clear(m)
println("cleared map:", m[1], m[2], m[3], len(m))
m[4] = "four"
println("added to cleared map:", m[1], m[2], m[3], m[4], len(m))
}
+2
View File
@@ -1,3 +1,5 @@
min/max: -3 5
min/max: -3.000000e+000 +5.000000e+000
cleared s[:3]: 0 0 0 4 5
cleared map: 0
added to cleared map: four 1