From 3e0c0a8add600cd395c4e30a4db8cc1ede90acc9 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 17 Oct 2011 12:53:10 -0700 Subject: [PATCH] go spec: "delete" built-in function R=golang-dev, r, rsc CC=golang-dev https://golang.org/cl/5272045 --- doc/go_spec.html | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 810df2c46a..4c1ecef353 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1159,9 +1159,10 @@ map [string] interface {} The number of map elements is called its length. For a map m, it can be discovered using the built-in function len(m) -and may change during execution. Elements may be added and removed -during execution using special forms of assignment; -and they may be accessed with index expressions. +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.

A new, empty map value is made using the built-in @@ -2431,21 +2432,6 @@ where the result of the index expression is a pair of values with types a[x] as in the single-result form.

-

-Similarly, if an assignment to a map element has the special form -

- -
-a[x] = v, ok
-
- -

-and boolean ok has the value false, -the entry for key x is deleted from the map; if -ok is true, the construct acts like -a regular assignment to an element of the map. -

-

Assigning to an element of a nil map causes a run-time panic. @@ -4738,6 +4724,27 @@ n2 := copy(s, s[2:]) // n2 == 4, s == []int{2, 3, 4, 5, 4, 5} n3 := copy(b, "Hello, World!") // n3 == 5, b == []byte("Hello") + +

Deletion of map elements

+ +

+The built-in function delete removes the element with key +k from a map m. The +type of k must be assignable +to the key type of m. +

+ +
+delete(m, k)  // remove element m[k] from map m
+
+ +

+If the element m[k] does not exist, delete is +a no-op. Calling delete with a nil map causes a +run-time panic. +

+ +

Assembling and disassembling complex numbers