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

x/blog: make snippet more flexible in slices blog #39240

Closed
AfrouzMashayekhi opened this issue May 25, 2020 · 6 comments · Fixed by AfrouzMashayekhi/blog#1
Closed

x/blog: make snippet more flexible in slices blog #39240

AfrouzMashayekhi opened this issue May 25, 2020 · 6 comments · Fixed by AfrouzMashayekhi/blog#1
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@AfrouzMashayekhi
Copy link

What version of Go are you using (go version)?

$ go version

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

in https://blog.golang.org/slices blog at Passing slices to functions can't change or play with AddOneToEachElement function.

What did you expect to see?

adding AddOneToEachElement function to the try it snippet to try or change the function.

What did you see instead?

unable to change AddOneToEachElement function.

@gopherbot gopherbot added this to the Unreleased milestone May 25, 2020
@AfrouzMashayekhi AfrouzMashayekhi changed the title x/blog: x/blog: make snippet more flexible in slices blog May 25, 2020
@ianlancetaylor
Copy link
Contributor

I'm sorry, I don't understand what you mean. Can you show an example of how you think the blog post should be changed? Thanks.

@ianlancetaylor ianlancetaylor added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label May 25, 2020
@AfrouzMashayekhi
Copy link
Author

AfrouzMashayekhi commented May 28, 2020

I think It's good to have

func AddOneToEachElement(slice []byte) {
    for i := range slice {
        slice[i]++
    }
}

in runnable snippet just like other functions in the blog.
for example:

func AddOneToEachElement(slice []byte) {
    for i := range slice {
        slice[i]++
    }
}
func main() {
    slice := buffer[10:20]
    for i := 0; i < len(slice); i++ {
        slice[i] = byte(i)
    }
    fmt.Println("before", slice)
    AddOneToEachElement(slice)
    fmt.Println("after", slice)
}

@Quaqmre
Copy link

Quaqmre commented May 30, 2020

Hi afrouzMashaykhi , if u want to run example code with custom slice manipulater function just write your custom function with different name in code area then change 'AddOneToEachElement' function name to your new function name.(u can click the code are and write some code)
image

I hope it will help u,

@AfrouzMashayekhi
Copy link
Author

yeah thanks @Quaqmre . But I think it will be good to have that option too, just like other functions in the blog. hom?

@Quaqmre
Copy link

Quaqmre commented May 30, 2020

Maybe u right it will be much helpfull for developers,but this issue releated with https://github.com/golang/blog project , u can reopen this issue on blog project ı think.

And I checked source code of gddo and snippets can doable more flexible with small changes,
If u want to make changes and send pull request look at
https://github.com/golang/blog/blob/master/content/slices.article
line of 185

.code slices/prog010.go /^func/,/^}/
to
.code -edit slices/prog010.go /^func/,/^}/
...

@AfrouzMashayekhi
Copy link
Author

@Quaqmre thanks for your help

@golang golang locked and limited conversation to collaborators May 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants