Remix.run Logo
rustandmore a day ago

Ownership is perfectly consistent.

`append` always returns a new slice value

`func append(slice []Type, elems ...Type) []Type`

The only correct way to use append is something like `sl = append(sl, 1, 2, 3)`

`sl` is now a new slice value, as `append` always returns a new slice value. You must now pass the new slice value back to the user, and the user must use the new slice value. The user must not use the old slice value.

It's trivial to fix the "bug" in the article, once you actually understand what a slice value is: https://go.dev/play/p/JRMV_IuXcZ6

A slice is not the underlying array, and the underlying array is not the slice. A slice is just a box with 3 numbers.