Skip to content

Commit

Permalink
Merge pull request #1977 from xushiwei/q
Browse files Browse the repository at this point in the history
mini spec: builtin clear
  • Loading branch information
xushiwei authored Sep 5, 2024
2 parents 30531d9 + dc46561 commit bf2dd08
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions doc/spec-mini.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bf2dd08

Please sign in to comment.