|
|
@@ -1,23 +1,19 @@
|
|
|
-# Chapter 4. Sequences
|
|
|
+# Глава 4. Последовательности
|
|
|
|
|
|
-We have said that a string is a sequence of characters. Nim also supports
|
|
|
-sequences, called seq, of an arbitrary type. For example, a sequence of
|
|
|
-integers is written with the notation seq[int], and a sequence of Point is
|
|
|
-seq[Point].
|
|
|
-We want to be able to draw more than a single pixel. putPixels accomplishes
|
|
|
-that:
|
|
|
+We have said that a string is a sequence of characters. Nim also supports sequences, called seq, of an arbitrary type. For example, a sequence of integers is written with the notation seq[int], and a sequence of Point is seq[Point].
|
|
|
+
|
|
|
+We want to be able to draw more than a single pixel. putPixels accomplishes that:
|
|
|
+
|
|
|
+```nim
|
|
|
proc putPixels(points: seq[Point]; col: Color) = 1
|
|
|
for p in items(points): 2
|
|
|
pixels.putPixel p.x, p.y, col 3
|
|
|
putPixels(@[Point(x: 2, y: 3), Point(x: 5, y: 10)], Gold) 4
|
|
|
- 1 putPixels takes a list of Points.
|
|
|
- 2 The items iterator allows us to iterate over the points parameter.
|
|
|
- 3 Every pixel we draw uses the same color col. We call the putPixel proc
|
|
|
- from the pixels module. As you can see, you can qualify an identifier
|
|
|
- with the module it was declared in. Sometimes this can improve the
|
|
|
- readability of your code.
|
|
|
- 4 We call our newly introduced putPixels proc with the seq @[Point(x: 2,
|
|
|
- y: 3), Point(x: 5, y: 10)].
|
|
|
-You can construct a sequence via @[...]. The empty sequence is @[].
|
|
|
-Sequences offer random access, the i'ith element can be accessed via s[i].
|
|
|
-The indexing starts from 0. The same notation is available for string.
|
|
|
+```
|
|
|
+
|
|
|
+- 1 putPixels takes a list of Points.
|
|
|
+- 2 The items iterator allows us to iterate over the points parameter.
|
|
|
+- 3 Every pixel we draw uses the same color col. We call the putPixel proc from the pixels module. As you can see, you can qualify an identifier with the module it was declared in. Sometimes this can improve the readability of your code.
|
|
|
+- 4 We call our newly introduced putPixels proc with the seq @[Point(x: 2, y: 3), Point(x: 5, y: 10)].
|
|
|
+
|
|
|
+You can construct a sequence via @[...]. The empty sequence is @[]. Sequences offer random access, the i'ith element can be accessed via s[i]. The indexing starts from 0. The same notation is available for string.
|