/* pop is the slice mutator's other half, and it is a STATEMENT only: pop(s) removes the last element pop(s, xs...) removes len(xs) elements - the mirror of push(s, xs...) There is no read form: `s[len(s)-1]` is the read and `s[len(s)-1:]` is the copy. `v := pop(s)` is a compile error - it used to return the value without shrinking, which meant two different things depending on whether the value was used. */ package main func main() { select { case <-shutdown: return default: } s := []string{"a", "b", "c", "d"} pop(s) if len(s) != 3 || s[2] != "c" { panic("pop(s) did not remove the last element") } drop := []string{"x", "y"} pop(s, drop...) if len(s) != 1 || s[0] != "a" { panic("pop(s, xs...) did not remove len(xs)") } last := s[len(s)-1] pop(s) if last != "a" || len(s) != 0 { panic("read then pop on a one-element slice") } k := []int32{5, 6} v := k[len(k)-1] if v != 6 || len(k) != 2 { panic("reading the last element must not shrink") } pop(k) if len(k) != 1 { panic("pop did not shrink") } println("pop forms ok") }