寻找golang's 2D slices和无法理解在最后一个例子中使用的语法:这个“常用成语”究竟是如何运作的?在文档
func main() {
XSize := 5
YSize := 5
// Allocate the top-level slice, the same as before.
picture := make([][]uint8, YSize) // One row per unit of y.
// Allocate one large slice to hold all the pixels.
pixels := make([]uint8, XSize*YSize) // Has type []uint8 even though picture is [][]uint8.
// Loop over the rows, slicing each row from the front of the remaining pixe ls slice.
for i := range picture {
picture[i], pixels = pixels[:XSize], pixels[XSize:]
}
}
我发现如果这被添加到文档和变化笔者有这个正常/易于理解的代码change request:
// Loop over the rows, slicing each row.
for i := range picture {
picture[i] = pixels[i*XSize:(i+1)*XSize]
然而,有这样的评论:
罚款。另一种常见的成语是为了避免数学:
picture[i], pixels = pixels[:XSize], pixels[XSize:]
我的问题是如何在上述实现同为“避免数学”方法?一些关于发生的事情的文档将会很棒。
敬畏的权利。完全合理。'(picture [i],pixels)=(pixels [:XSize],pixels [XSize:])'。只是没有看到这种方式。 – Jonathan