Skip to content

Commit 99bc53f

Browse files
cuonglmgopherbot
authored andcommitted
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>
1 parent 2baf8ad commit 99bc53f

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

doc/go_spec.html

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--{
22
"Title": "The Go Programming Language Specification",
3-
"Subtitle": "Version of February 14, 2023",
3+
"Subtitle": "Version of February 20, 2023",
44
"Path": "/ref/spec"
55
}-->
66

@@ -1644,8 +1644,10 @@ <h3 id="Map_types">Map types</h3>
16441644
and may change during execution. Elements may be added during execution
16451645
using <a href="#Assignment_statements">assignments</a> and retrieved with
16461646
<a href="#Index_expressions">index expressions</a>; they may be removed with the
1647-
<a href="#Deletion_of_map_elements"><code>delete</code></a> built-in function.
1647+
<a href="#Deletion_of_map_elements"><code>delete</code></a> and
1648+
<a href="#Clear"><code>clear</code></a> built-in function.
16481649
</p>
1650+
16491651
<p>
16501652
A new, empty map value is made using the built-in
16511653
function <a href="#Making_slices_maps_and_channels"><code>make</code></a>,
@@ -2316,7 +2318,7 @@ <h3 id="Predeclared_identifiers">Predeclared identifiers</h3>
23162318
nil
23172319

23182320
Functions:
2319-
append cap close complex copy delete imag len
2321+
append cap clear close complex copy delete imag len
23202322
make new panic print println real recover
23212323
</pre>
23222324

@@ -7181,6 +7183,36 @@ <h2 id="Built-in_functions">Built-in functions</h2>
71817183
they cannot be used as function values.
71827184
</p>
71837185

7186+
<h3 id="Clear">Clear</h3>
7187+
7188+
<p>
7189+
The built-in function <code>clear</code> takes an argument of <a href="#Map_types">map</a>,
7190+
<a href="#Slice_types">slice</a>, or <a href="#Type_parameter_declarations">type parameter</a> type,
7191+
and deletes or zeroes out all elements.
7192+
</p>
7193+
7194+
<pre class="grammar">
7195+
Call Argument type Result
7196+
7197+
clear(m) map[K]T deletes all entries, resulting in an
7198+
empty map (len(m) == 0)
7199+
7200+
clear(s) []T sets all elements up to the length of
7201+
<code>s</code> to the zero value of T
7202+
7203+
clear(t) type parameter see below
7204+
</pre>
7205+
7206+
<p>
7207+
If the argument type is a <a href="#Type_parameter_declarations">type parameter</a>,
7208+
all types in its type set must be maps or slices, and <code>clear</code>
7209+
performs the operation corresponding to the actual type argument.
7210+
</p>
7211+
7212+
<p>
7213+
If the map or slice is <code>nil</code>, <code>clear</code> is a no-op.
7214+
</p>
7215+
71847216
<h3 id="Close">Close</h3>
71857217

71867218
<p>

0 commit comments

Comments
 (0)