Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tour: Incorrect slicing behaviour on local AND remote gotour #43

Closed
half-adder opened this issue Jul 8, 2016 · 1 comment
Closed

tour: Incorrect slicing behaviour on local AND remote gotour #43

half-adder opened this issue Jul 8, 2016 · 1 comment

Comments

@half-adder
Copy link

Context: http://127.0.0.1:3999/moretypes/10

given s := []int{2, 3, 5, 7, 11, 13}, s[1:4] gives [3 5 7]. This is correct. However, s[:4] gives [3 5 7 11] this is clearly incorrect. Here is the complete code:

package main

import "fmt"

func main() {
    s := []int{2, 3, 5, 7, 11, 13}

    s = s[1:4]
    fmt.Println(s)

    s = s[:4]
    fmt.Println(s)
}

and the output:

[3 5 7]
[3 5 7 11]

Program exited.

The same behavior is present at https://tour.golang.org/moretypes/10

@half-adder
Copy link
Author

First statement mutates the slice object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant