diff options
author | Cuong Manh Le <cuong.manhle.vn@gmail.com> | 2023-02-14 00:10:10 +0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-02-20 02:28:50 +0000 |
commit | 99bc53f5e819c2d2d49f2a56c488898085be3982 (patch) | |
tree | 2aa025ecce00ae07d2df5ef261c5112e1a0de6e2 /doc | |
parent | 2baf8ad8311a9eb2c7d0352f32c46fb0e8b4afbe (diff) | |
download | go-git-99bc53f5e819c2d2d49f2a56c488898085be3982.tar.gz |
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 <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'doc')
-rw-r--r-- | doc/go_spec.html | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/doc/go_spec.html b/doc/go_spec.html index 941a2055f4..cbcaf3a338 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ <!--{ "Title": "The Go Programming Language Specification", - "Subtitle": "Version of February 14, 2023", + "Subtitle": "Version of February 20, 2023", "Path": "/ref/spec" }--> @@ -1644,8 +1644,10 @@ built-in function <a href="#Length_and_capacity"><code>len</code></a> and may change during execution. Elements may be added during execution using <a href="#Assignment_statements">assignments</a> and retrieved with <a href="#Index_expressions">index expressions</a>; they may be removed with the -<a href="#Deletion_of_map_elements"><code>delete</code></a> built-in function. +<a href="#Deletion_of_map_elements"><code>delete</code></a> and +<a href="#Clear"><code>clear</code></a> built-in function. </p> + <p> A new, empty map value is made using the built-in function <a href="#Making_slices_maps_and_channels"><code>make</code></a>, @@ -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 </pre> @@ -7181,6 +7183,36 @@ so they can only appear in <a href="#Calls">call expressions</a>; they cannot be used as function values. </p> +<h3 id="Clear">Clear</h3> + +<p> +The built-in function <code>clear</code> takes an argument of <a href="#Map_types">map</a>, +<a href="#Slice_types">slice</a>, or <a href="#Type_parameter_declarations">type parameter</a> type, +and deletes or zeroes out all elements. +</p> + +<pre class="grammar"> +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 + <code>s</code> to the zero value of T + +clear(t) type parameter see below +</pre> + +<p> +If the argument type is a <a href="#Type_parameter_declarations">type parameter</a>, +all types in its type set must be maps or slices, and <code>clear</code> +performs the operation corresponding to the actual type argument. +</p> + +<p> +If the map or slice is <code>nil</code>, <code>clear</code> is a no-op. +</p> + <h3 id="Close">Close</h3> <p> |