递归追加到切片不起作用

I'm trying to learn Go but I can't figure it out why this code at the end of the recursion call stack returns an empty slice, any help? Also tmp doesn't even seem to register in the debugger.

func main() {
    input := [3]int{4, 6, 7}
    // expected [[6,7],[4,6,7],[4,6],[4,7]]
    fmt.Println(findSubsequences(input))
}

func findSubsequences(nums [3]int) [][]int {
    res := [][]int{}
    list := []int{}
    findSubsequence(res, list, nums, 0)
    return res
}

func findSubsequence(res [][]int, list []int, nums [3]int, id int) [][]int {
    if len(list) > 1 {
        tmp := make([]int, len(list))
        copy(tmp, list)
        res = append(res, tmp)
    }
    var unique []int
    for i := id; i < len(nums); i++ {
        if id > 0 && nums[i] < nums[id-1] {
            continue // skip non-increase
        }
        if contains(unique, nums[i]) {
            continue // skip duplicate
        }
        unique = append(unique, nums[i])
        list = append(list, nums[i])
        findSubsequence(res, list, nums, id+1)
        list = list[:len(list)-1]
    }
    return res
}

func contains(s []int, e int) bool {
    for _, a := range s {
        if a == e {
            return true
        }
    }
    return false
}

This is the solution to get your code to append the slice. In GO, if you are recursively passing a slice, you must pass it by reference. So this solves the problem that you are experiencing where your code will return empty slice. But your algorithm seems incorrect for the result that you are expecting.

func main() {
    input := [3]int{4, 6, 7}
    // expected [[6,7],[4,6,7],[4,6],[4,7]]
    fmt.Println(findSubsequences(input))
}

func findSubsequences(nums [3]int) [][]int {
    res := [][]int{}
    list := []int{}
    fmt.Print(nums)
    findSubsequence(&res, list, nums, 0)
    return res
}

func findSubsequence(res *[][]int, list []int, nums [3]int, id int) [][]int {
    var tmp []int
    if len(list) > 1 {
        tmp = make([]int, len(list))
        copy(tmp, list)
    fmt.Println(tmp)
        *res = append(*res, tmp)
    }
    var unique []int
    for i := id; i < len(nums); i++ {
        if id > 0 && nums[i] < nums[id-1] {
            continue // skip non-increase
        }
        if contains(unique, nums[i]) {
            continue // skip duplicate
        }
        unique = append(unique, nums[i])
        list = append(list, nums[i])
        findSubsequence(res, list, nums, id+1)
    list = list[:len(list)-1]

    }
    return *res
}

func contains(s []int, e int) bool {
    for _, a := range s {
        if a == e || a >e {
            return true
        }
    }
    return false
}

I used global variables in the end, but is still not OK, it works slower than Java, anyway here is the code.

var res = [][]int{}
var list = []int{}

func findSubsequences(nums [3]int) [][]int {
    findSubsequence(nums, 0)
    return res
}

func findSubsequence(nums [3]int, id int) {
    if len(list) > 1 {
        tmp := make([]int, len(list))
        copy(tmp, list)
        res = append(res, tmp)
    }
    var unique []int
    for i := id; i < len(nums); i++ {
        if id > 0 && nums[i] < nums[id-1] {
            continue // skip non-increase
        }
        if contains(unique, nums[i]) {
            continue // skip duplicate
        }
        unique = append(unique, nums[i])
        list = append(list, nums[i])
        findSubsequence(nums, i+1)
        list = list[:len(list)-1]
    }
}

func contains(s []int, e int) bool {
    for _, a := range s {
        if a == e {
            return true
        }
    }
    return false
}