Thank you. I am sure I read that blog post before, but I didn't understand 
the ramifications. For performance reasons it makes sense, but it remains a 
bit unexpected to me that rest := append(slice[:i], slice[j:]...) and rest 
:= slices.Delete(slice, i, j) have a side effect on slice (as documented in 
slices.Delete). Thank you again.
On Friday, November 7, 2025 at 7:13:53 PM UTC+1 Ian Lance Taylor wrote:

> On Fri, Nov 7, 2025 at 9:47 AM Roel van der Goot
> <[email protected]> wrote:
> >
> > package main
> >
> > import "fmt"
> >
> > func main() {
> > slice := []int{1, 2}
> > rest := append(slice[:0], slice[1:]...)
> > fmt.Printf("slice = %+v, rest = %+v\n", slice, rest)
> > }
> >
> > Actual output:
> > slice = [2 2], rest = [2]
> > Expected output:
> > slice = [1 2], rest = [2]
> >
> > https://go.dev/play/p/GU5h_45dPg9
> >
> > Go 1.25.3 and 1.25.4
> >
> > Am I missing something?
>
> Please see https://go.dev/blog/slices .
>
> Ian
>

-- 
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 [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/40b589fa-b056-4a42-9ae8-2a9433cf4e01n%40googlegroups.com.

Reply via email to