Skip to content

Commit

Permalink
doc: add clear builtin to spec
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cuonglm authored and gopherbot committed Feb 20, 2023
1 parent 2baf8ad commit 99bc53f
Showing 1 changed file with 35 additions and 3 deletions.
38 changes: 35 additions & 3 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
@@ -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"
}-->

Expand Down Expand Up @@ -1644,8 +1644,10 @@ <h3 id="Map_types">Map types</h3>
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>,
Expand Down Expand Up @@ -2316,7 +2318,7 @@ <h3 id="Predeclared_identifiers">Predeclared identifiers</h3>
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>

Expand Down Expand Up @@ -7181,6 +7183,36 @@ <h2 id="Built-in_functions">Built-in functions</h2>
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>
Expand Down

0 comments on commit 99bc53f

Please sign in to comment.