From 99bc53f5e819c2d2d49f2a56c488898085be3982 Mon Sep 17 00:00:00 2001 From: Cuong Manh Le Date: Tue, 14 Feb 2023 00:10:10 +0700 Subject: [PATCH] doc: add clear builtin to spec Fixes #56351 Change-Id: Ia87bf594553b7d0464b591106840f849571c5f39 Reviewed-on: https://go-review.googlesource.com/c/go/+/467755 Auto-Submit: Cuong Manh Le Reviewed-by: Matthew Dempsky Run-TryBot: Cuong Manh Le Reviewed-by: Robert Griesemer TryBot-Bypass: Robert Griesemer Auto-Submit: Robert Griesemer TryBot-Result: Gopher Robot --- doc/go_spec.html | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 941a2055f49..cbcaf3a3385 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1644,8 +1644,10 @@ built-in function len and may change during execution. Elements may be added during execution using assignments and retrieved with index expressions; they may be removed with the -delete built-in function. +delete and +clear built-in function.

+

A new, empty map value is made using the built-in function make, @@ -2316,7 +2318,7 @@ Zero value: nil Functions: - append cap close complex copy delete imag len + append cap clear close complex copy delete imag len make new panic print println real recover @@ -7181,6 +7183,36 @@ so they can only appear in call expressions; they cannot be used as function values.

+

Clear

+ +

+The built-in function clear takes an argument of map, +slice, or type parameter type, +and deletes or zeroes out all elements. +

+ +
+Call        Argument type     Result
+
+clear(m)    map[K]T           deletes all entries, resulting in an
+                              empty map (len(m) == 0)
+
+clear(s)    []T               sets all elements up to the length of
+                              s to the zero value of T
+
+clear(t)    type parameter    see below
+
+ +

+If the argument type is a type parameter, +all types in its type set must be maps or slices, and clear +performs the operation corresponding to the actual type argument. +

+ +

+If the map or slice is nil, clear is a no-op. +

+

Close