|
|
@@ -1,19 +1,19 @@
|
|
|
# Глава 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].
|
|
|
+Ранее уже было указано, что строка — это последовательность символов. **Nim** также поддерживает последовательности произвольного типа, называемые `seq`. Например, последовательность целых чисел записывается как `seq[int]`, а последовательность объектов `Point` — как `seq[Point]`.
|
|
|
|
|
|
-We want to be able to draw more than a single pixel. putPixels accomplishes that:
|
|
|
+Мы хотим иметь возможность рисовать не только отдельные пиксели. Процедура `putPixels` позволяет это сделать:
|
|
|
|
|
|
```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
|
|
|
+ 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)].
|
|
|
+- 1 `putPixels` принимает список точек.
|
|
|
+- 2 Итератор `items` позволяет перебирать параметр `points`.
|
|
|
+- 3 Каждый нарисованный нами пиксель имеет один и тот же цвет `col`. Вызов процедуры `putPixel` выполняется из модуля `pixels`. Как можно видеть, идентификатор можно дополнить указанием модуля, в котором он был объявлен. Иногда это улучшает читаемость кода.
|
|
|
+- 4 Вызов новой процедуры `putPixels` с помощью помлеовательности `@[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.
|
|
|
+Последовательность можно создать с помощью `@[...]`. Пустая последовательность — в виде `@[]`. Последовательности обеспечивают произвольный доступ: доступ к `i`-му элементу можно получить через `s[i]`. Индексация начинается с 0. Такое же обозначение доступно для строк.
|