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:]
私の質問は、上記の「数学を避ける」方法と同じを達成んどのようにでしょうか?何が起こっているのかについてのいくつかのドキュメントは素晴らしいでしょう。
素晴らしい。全く意味をなさない。'(ピクチャ[i]、ピクセル)=(ピクセル[:XSize]、ピクセル[XSize:])'。そのように見ていないだけでした。 – Jonathan