Pass slice to a function

Here is an example of slice passed as value to a function:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

func main() {
    dirs := []string{"up", "down", "left", "right"}
    up(dirs)

    // dirs => []string{"UP", "DOWN", "LEFT", "RIGHT"}
}

func up(list []string) {
    // slice pointer points to a reference
    // even if they passed in a function.
    // So it modify the original slice
    // elements to upper case.
    for i := range list{
        list[i] = strings.ToUpper(list[i])
    }

    // Here append function only modifies
    // the copy of slice. So the original slice
    // if unaffected by append function.
    list = append(list, "HEISEN BUG")
}

Here is the link for slice internals.