FAQ
Hi Jesse,

I just want to replace the value of the slice.E.g.:

slice := []int{1, 2}
slice[2:] = append(slice[2:], 3)

just want to add 3 in the slice[2].

Best Regards
Nan Xiao
On Mon, Mar 21, 2016 at 9:23 AM, Peter Weinberger wrote:

There are languages in which that would work (e.g., R) to replace part of
the slice, but Go is not such a language.

On Sun, Mar 20, 2016 at 9:15 PM, Jesse McNelis wrote:

On Mon, Mar 21, 2016 at 12:08 PM, Nan Xiao <xiaonan830818@gmail.com>
wrote:
Hi all,

Just curious, why the following statements make a compile error: "cannot
assign to slice[2:]"?

slice := []int{1, 2}
slice[2:] = append(slice[2:], 3)
slice[2:] is a value, it's not a variable.
What would you expect the result of this statement to be?

--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 4 of 8 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedMar 21, '16 at 1:08a
activeMar 24, '16 at 3:09p
posts8
users6
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase