From dc46561b88cfaed543747cfa8fbf6e53d271cac1 Mon Sep 17 00:00:00 2001 From: xushiwei Date: Fri, 6 Sep 2024 07:35:02 +0800 Subject: [PATCH] mini spec: builtin clear --- doc/spec-mini.md | 20 ++++++++++++++++++++ doc/spec.md | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/doc/spec-mini.md b/doc/spec-mini.md index cf9346233..e33252b20 100644 --- a/doc/spec-mini.md +++ b/doc/spec-mini.md @@ -1453,3 +1453,23 @@ n1 := copy(s, a) // n1 == 6, s is []int{0, 1, 2, 3, 4, 5} n2 := copy(s, s[2:]) // n2 == 4, s is []int{2, 3, 4, 5, 4, 5} n3 := copy(b, "Hello, World!") // n3 == 5, b is []byte("Hello") ``` + +### Clear + +The built-in function `clear` takes an argument of `map` or `slice` and deletes or zeroes out all elements. + +``` +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 + s to the zero value of T +``` + +If the map or slice is `nil`, `clear` is a no-op. + +### Manipulating complex numbers + +TODO diff --git a/doc/spec.md b/doc/spec.md index 496910981..60206edcf 100644 --- a/doc/spec.md +++ b/doc/spec.md @@ -264,3 +264,24 @@ TODO See [Conversions](spec-mini.md#conversions). TODO + + +## Statements + +TODO + +## Built-in functions + +### Appending to and copying slices + +See [Appending to and copying slices](spec-mini.md#appending-to-and-copying-slices). + +### Clear + +TODO + +### Close + +TODO + +### Manipulating complex numbers