|
1 | 1 | <!--{
|
2 | 2 | "Title": "The Go Programming Language Specification",
|
3 |
| - "Subtitle": "Version of February 14, 2023", |
| 3 | + "Subtitle": "Version of February 20, 2023", |
4 | 4 | "Path": "/ref/spec"
|
5 | 5 | }-->
|
6 | 6 |
|
@@ -1644,8 +1644,10 @@ <h3 id="Map_types">Map types</h3>
|
1644 | 1644 | and may change during execution. Elements may be added during execution
|
1645 | 1645 | using <a href="#Assignment_statements">assignments</a> and retrieved with
|
1646 | 1646 | <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. |
1648 | 1649 | </p>
|
| 1650 | + |
1649 | 1651 | <p>
|
1650 | 1652 | A new, empty map value is made using the built-in
|
1651 | 1653 | function <a href="#Making_slices_maps_and_channels"><code>make</code></a>,
|
@@ -2316,7 +2318,7 @@ <h3 id="Predeclared_identifiers">Predeclared identifiers</h3>
|
2316 | 2318 | nil
|
2317 | 2319 |
|
2318 | 2320 | Functions:
|
2319 |
| - append cap close complex copy delete imag len |
| 2321 | + append cap clear close complex copy delete imag len |
2320 | 2322 | make new panic print println real recover
|
2321 | 2323 | </pre>
|
2322 | 2324 |
|
@@ -7181,6 +7183,36 @@ <h2 id="Built-in_functions">Built-in functions</h2>
|
7181 | 7183 | they cannot be used as function values.
|
7182 | 7184 | </p>
|
7183 | 7185 |
|
| 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 | + |
7184 | 7216 | <h3 id="Close">Close</h3>
|
7185 | 7217 |
|
7186 | 7218 | <p>
|
|
0 commit comments