修复数组替换中引用不正确的切片

The following go code doesn't compile, because (I believe) there is a mistake around the way pointers are being referenced.

In particular, The error message is

prog.go:13: cannot use append((*x)[:remove], (*x)[remove + 1:]...) (type []int) as type *[]int in assignment

Here is an abstracted and simplified version of the code which results in this error message.

package main

import "fmt"

func main() {

    x := &[]int{11, 22, 33, 44, 55, 66, 77, 88, 99}

    for i, addr := range *x {
        if addr == 22 {
            for len(*x) > 5 {
                remove := (i + 1) % len(*x)
                x = append((*x)[:remove], (*x)[remove+1:]...)
            }
            break
        }
    }

    fmt.Println(x)
}

You're not using an array here, you're using a slice. Generally, you don't want to handle a pointer to a slice since it can get awkward, and the pointer is needed in very few cases.

To fix your error, dereference x:

*x = append((*x)[:remove], (*x)[remove+1:]...)

But you should probably be using the slice value directly, so that no dereferences are required:

x := []int{11, 22, 33, 44, 55, 66, 77, 88, 99}