|
|
@@ -1,12 +1,12 @@
|
|
|
-# Chapter 10. Macros
|
|
|
+# Глава 10. Макросы
|
|
|
|
|
|
-As we have seen templates can be used for tasks where ordinary procs fail. In some sense a template is more powerful than a proc. A macro is even more powerful than a template because a macro can inspect a body of code that is passed to it.
|
|
|
+Как мы уже видели, шаблоны можно использовать для решения задач, с которыми не справляются обычные процедуры. В некотором смысле шаблон мощнее процедуры. Макрос еще мощнее шаблона, потому что он может анализировать передаваемый ему блок кода.
|
|
|
|
|
|
-The first macro can be very hard to understand because you don’t write the pattern that is expanded where the macro is invoked as you would for a template. Instead you write the instructions on how to create the pattern that is the code that is inserted where the macro is invoked.
|
|
|
+Первый макрос может показаться очень сложным для понимания, потому что вы не пишете шаблон, который раскрывается при вызове макроса, как в случае с шаблоном. Вместо этого вы пишете инструкции по созданию шаблона — кода, который вставляется при вызове макроса.
|
|
|
|
|
|
-In other words the code is rather imperative and low level.
|
|
|
+Другими словами, код довольно императивный и низкоуровневый.
|
|
|
|
|
|
-The following example is a macro that turns the body of code that it receives into an empty list of statements (newStmtList()). This means that the body of code is ignored by the compiler:
|
|
|
+Следующий пример — макрос, который преобразует полученный блок кода в пустой список операторов (`newStmtList()`). Это означает, что блок кода игнорируется компилятором:
|
|
|
|
|
|
```nim
|
|
|
import std/macros # 1
|
|
|
@@ -16,11 +16,9 @@ The following example is a macro that turns the body of code that it receives in
|
|
|
drawText(10, 10, "Disabled piece of code!", Blue)
|
|
|
```
|
|
|
|
|
|
-- 1 To work with macros an API is required, this API is in std/macros.
|
|
|
-- 2 The macro declaration looks like the template declaration except that the keyword template was replaced by macro.
|
|
|
-- 3 The result of the macro is a syntax tree that is an empty list of statements.
|
|
|
-- 4 To invoke a macro, the same syntax is used as for procs and templates.
|
|
|
+- 1 Для работы с макросами требуется **API**, который находится в `std/macros`.
|
|
|
+- 2 Объявление макроса похоже на объявление шаблона, за исключением того, что ключевое слово `template` заменено на `macro`.
|
|
|
+- 3 Результатом работы макроса является синтаксическое дерево, представляющее собой пустой список операторов.
|
|
|
+- 4 Для вызова макроса используется тот же синтаксис, что и для процедур и шаблонов.
|
|
|
|
|
|
-Many more examples for macros can be found throughout the book but the
|
|
|
-better examples are too advanced for this introduction.
|
|
|
-And with this our first tour through Nim ends. Time to dive into the foxhole!
|
|
|
+В книге можно найти множество примеров использования макросов, но лучшие из них слишком сложны для этого вводного раздела. На этом наш первый экскурс в **Nim** заканчивается. Пора нырять в окоп!
|