I
I
Ilya2018-05-23 14:04:06
go
Ilya, 2018-05-23 14:04:06

Why can't slice capacity in Golang be extended in the opposite direction (to the left)?

Why is the cutting capacity permanently cut on the left side?
For example, from the training tour , you can understand if we cut the original array/slice c to its value, it can be restored to its original form , but if we cut the same array/slice from the left side, for example, then it can no longer be restored. What causes such mechanics? Why not do reverse indexing like in Python for example?
arr := []int{1, 2, 3, 4, 5}
arr = arr[:0] // []
arr = arr[:5] // [1 2 3 4 5]
arr = arr[5:] // []

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question