From 3f0b3a64c07afa74d7523a558c642b45af795e8b Mon Sep 17 00:00:00 2001 From: zihang Date: Thu, 26 Dec 2024 14:44:21 +0800 Subject: [PATCH] doc(i18n): translate control flow --- next/locales/zh_CN/LC_MESSAGES/language.po | 250 ++++++++++++--------- next/sources/language/src/iter/top.mbt | 22 +- 2 files changed, 157 insertions(+), 115 deletions(-) diff --git a/next/locales/zh_CN/LC_MESSAGES/language.po b/next/locales/zh_CN/LC_MESSAGES/language.po index b8304ad5..45d0bb92 100644 --- a/next/locales/zh_CN/LC_MESSAGES/language.po +++ b/next/locales/zh_CN/LC_MESSAGES/language.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: MoonBit Document \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-12-23 15:22+0800\n" +"POT-Creation-Date: 2024-12-26 14:41+0800\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language: zh_CN\n" @@ -2554,17 +2554,17 @@ msgstr "自动填充参数非常有用,用于编写调试和测试工具。" #: ../../language/fundamentals.md:501 msgid "Control Structures" -msgstr "" +msgstr "控制结构" #: ../../language/fundamentals.md:503 msgid "Conditional Expressions" -msgstr "" +msgstr "条件表达式" #: ../../language/fundamentals.md:505 msgid "" "A conditional expression consists of a condition, a consequent, and an " "optional `else` clause or `else if` clause." -msgstr "" +msgstr "条件表达式由条件、结果和可选的 `else` 子句或 `else if` 子句组成。" #: ../../language/fundamentals.md:507 msgid "" @@ -2579,14 +2579,14 @@ msgstr "" #: ../../language/fundamentals.md:514 msgid "The curly brackets around the consequent are required." -msgstr "" +msgstr "结果周围的大括号是必需的。" #: ../../language/fundamentals.md:516 msgid "" "Note that a conditional expression always returns a value in MoonBit, and" " the return values of the consequent and the else clause must be of the " "same type. Here is an example:" -msgstr "" +msgstr "请注意,条件表达式在 MoonBit 中始终返回一个值,结果和 else 子句的返回值必须是相同的类型。以下是一个示例:" #: ../../language/fundamentals.md:518 msgid "let initial = if size < 1 { 1 } else { size }\n" @@ -2594,18 +2594,18 @@ msgstr "" #: ../../language/fundamentals.md:525 msgid "The `else` clause can only be omitted if the return value has type `Unit`." -msgstr "" +msgstr "`else` 子句只有在返回值的类型为 `Unit`的时候省略。" #: ../../language/fundamentals.md:527 msgid "Match Expression" -msgstr "" +msgstr "匹配表达式" #: ../../language/fundamentals.md:529 msgid "" "The `match` expression is similar to conditional expression, but it uses " "[pattern matching](#pattern-matching) to decide which consequent to " "evaluate and extracting variables at the same time." -msgstr "" +msgstr "`match` 表达式类似于条件表达式,但它使用[模式匹配](#pattern-matching)来决定要评估哪个结果,并同时提取变量。" #: ../../language/fundamentals.md:531 msgid "" @@ -2626,11 +2626,11 @@ msgstr "" msgid "" "If a possible condition is omitted, the compiler will issue a warning, " "and the program will terminate if that case were reached." -msgstr "" +msgstr "如果省略了可能的条件,编译器将发出警告;如果真的出现该情况,程序将终止。" #: ../../language/fundamentals.md:540 msgid "Guard Statement" -msgstr "" +msgstr "卫语句" #: ../../language/fundamentals.md:542 msgid "" @@ -2640,6 +2640,8 @@ msgid "" "(i.e., false), the code in the `else` block is executed and its " "evaluation result is returned (the subsequent statements are skipped)." msgstr "" +"`guard` 语句用于检查指定的不变量。如果不变量的条件得到满足,程序将继续执行后续语句。如果条件不满足(即为假),则执行 `else` " +"块中的代码且返回其值(并跳过后续语句)。" #: ../../language/fundamentals.md:547 msgid "" @@ -2655,7 +2657,7 @@ msgstr "" #: ../../language/fundamentals.md:554 msgid "Guarded Let" -msgstr "" +msgstr "卫语句与赋值绑定" #: ../../language/fundamentals.md:556 msgid "" @@ -2663,6 +2665,8 @@ msgid "" "matching). However, `let` statement can only handle one case. And `guard " "let` can solve this issue." msgstr "" +"`let` 语句可以与[模式匹配](#pattern-matching)一起使用。但是,`let` 语句只能处理一种情况。`guard let` " +"可以解决这个问题。" #: ../../language/fundamentals.md:558 msgid "" @@ -2672,6 +2676,8 @@ msgid "" "statement, the subsequent processing of `text` can have one less level of" " indentation." msgstr "" +"在以下示例中,`getProcessedText` 假设输入的 `path` 指向的资源都是纯文本,并使用 `guard` " +"语句来确保这个不变量。与使用 `match` 语句相比,`text` 的后续处理可以少一级缩进。" #: ../../language/fundamentals.md:562 msgid "" @@ -2698,7 +2704,7 @@ msgstr "" msgid "" "When the `else` part is omitted, the program terminates if the condition " "specified in the `guard` statement is not true or cannot be matched." -msgstr "" +msgstr "如果省略了 `else` 部分,程序将在 `guard` 语句中指定的条件不为真或无法匹配时终止。" #: ../../language/fundamentals.md:571 msgid "" @@ -2709,7 +2715,7 @@ msgstr "" #: ../../language/fundamentals.md:578 msgid "While loop" -msgstr "" +msgstr "While 循环" #: ../../language/fundamentals.md:580 msgid "" @@ -2720,6 +2726,8 @@ msgid "" "body is a sequence of statements. The loop body is executed as long as " "the condition is true." msgstr "" +"在 MoonBit 中,`while` 循环可用于在条件为真时重复执行一段代码块。在执行代码块之前,将评估条件。使用 `while` 关键字定义 " +"`while` 循环,后跟条件和循环体。循环体是一系列语句。只要条件为真,就会执行循环体。" #: ../../language/fundamentals.md:582 msgid "" @@ -2747,6 +2755,8 @@ msgid "" "to exit the current loop, while using `continue` skips the remaining part" " of the current iteration and proceeds to the next iteration." msgstr "" +"循环体支持 `break` 和 `continue`。使用 `break` 可以退出当前循环,而使用 `continue` " +"则跳过当前迭代的剩余部分并继续下一次迭代。" #: ../../language/fundamentals.md:596 msgid "" @@ -2776,7 +2786,7 @@ msgid "" "The `while` loop also supports an optional `else` clause. When the loop " "condition becomes false, the `else` clause will be executed, and then the" " loop will end." -msgstr "" +msgstr "`while` 循环还支持可选的 `else` 子句。当循环条件变为假时,将执行 `else` 子句,然后循环将结束。" #: ../../language/fundamentals.md:610 msgid "" @@ -2806,6 +2816,8 @@ msgid "" "value after `break`, which should be of the same type as the return value" " of the `else` clause." msgstr "" +"当有 `else` 子句时,`while` 循环还可以返回一个值。返回值是 `else` 子句的评估结果。在这种情况下,如果使用 `break` " +"退出循环,需要在 `break` 后提供一个返回值,该返回值应与 `else` 子句的返回值类型相同。" #: ../../language/fundamentals.md:624 msgid "" @@ -2846,7 +2858,7 @@ msgstr "" #: ../../language/fundamentals.md:648 msgid "For Loop" -msgstr "" +msgstr "For 循环" #: ../../language/fundamentals.md:650 msgid "" @@ -2857,6 +2869,9 @@ msgid "" " a scope throughout the entire loop and is immutable. This makes it " "easier to write clear code and reason about it:" msgstr "" +"MoonBit 还支持 C 风格的 For 循环。关键字 `for` " +"后跟由分号分隔的变量初始化子句、循环条件和更新子句。它们不需要用括号括起来。例如,下面的代码创建了一个新的变量绑定 " +"`i`,它在整个循环中都有作用域且是不可变的。这使得编写清晰的代码并对其进行推理更容易:" #: ../../language/fundamentals.md:653 msgid "" @@ -2878,7 +2893,7 @@ msgstr "" #: ../../language/fundamentals.md:665 msgid "The variable initialization clause can create multiple bindings:" -msgstr "" +msgstr "变量初始化子句可以创建多个绑定:" #: ../../language/fundamentals.md:667 msgid "" @@ -2897,12 +2912,14 @@ msgid "" "variables in the update clause, you will always get the values updated in" " the previous iteration." msgstr "" +"应该注意,在更新子句中,当有多个绑定变量时,语义是同时更新它们。换句话说,在上面的示例中,更新子句不会按顺序执行 `i = i + 1`,`j =" +" j + 1`,而是同时递增 `i` 和 `j`。因此,在更新子句中读取绑定变量的值时,总是会得到上一次迭代中更新的值。" #: ../../language/fundamentals.md:676 msgid "" "Variable initialization clauses, loop conditions, and update clauses are " "all optional. For example, the following two are infinite loops:" -msgstr "" +msgstr "变量初始化子句、循环条件和更新子句都是可选的。例如,以下两个是无限循环:" #: ../../language/fundamentals.md:678 msgid "" @@ -2920,6 +2937,8 @@ msgid "" "Like the `while` loop, the `for` loop can also return a value using the " "`break` and `else` clauses." msgstr "" +"`for` 循环还支持 `continue`、`break` 和 `else` 子句。与 `while` 循环一样,`for` 循环也可以使用 " +"`break` 和 `else` 子句返回一个值。" #: ../../language/fundamentals.md:687 msgid "" @@ -2929,12 +2948,14 @@ msgid "" " variables of the `for` loop, as long as it is followed by expressions " "that match the number of binding variables, separated by commas." msgstr "" +"`continue` 语句跳过当前 `for` 循环的剩余部分(包括更新子句)并继续下一次迭代。`continue` 语句还可以更新 `for` " +"循环的绑定变量,只要后面跟着与绑定变量数量匹配的表达式,用逗号分隔。" #: ../../language/fundamentals.md:689 msgid "" "For example, the following program calculates the sum of even numbers " "from 1 to 6:" -msgstr "" +msgstr "例如,以下程序计算从 1 到 6 的偶数之和:" #: ../../language/fundamentals.md:691 msgid "" @@ -2961,13 +2982,13 @@ msgstr "" #: ../../language/fundamentals.md:703 msgid "`for .. in` loop" -msgstr "" +msgstr "`for .. in` 循环" #: ../../language/fundamentals.md:705 msgid "" "MoonBit supports traversing elements of different data structures and " "sequences via the `for .. in` loop syntax:" -msgstr "" +msgstr "MoonBit 支持通过 `for .. in` 循环语法遍历不同数据结构和序列的元素:" #: ../../language/fundamentals.md:707 msgid "" @@ -2983,12 +3004,14 @@ msgid "" "using `for .. in`. For more information of the `Iter` type, see " "[Iterator](#iterator) below." msgstr "" +"`for .. in` 循环被转换为在 MoonBit 标准库中使用 `Iter`。任何具有方法 `.iter() : Iter[T]` " +"的类型都可以使用 `for .. in` 进行遍历。有关 `Iter` 类型的更多信息,请参见下面的[迭代器](#iterator)。" #: ../../language/fundamentals.md:717 msgid "" "`for .. in` loop also supports iterating through a sequence of integers, " "such as:" -msgstr "" +msgstr "`for .. in` 循环还支持遍历整数序列,例如:" #: ../../language/fundamentals.md:719 msgid "" @@ -3014,6 +3037,8 @@ msgid "" "in MoonBit's standard library. Any type with method `.iter2() : Iter2[A, " "B]` can be traversed using `for .. in` with two loop variables:" msgstr "" +"除了单个值的序列外,MoonBit 还支持通过 MoonBit 标准库中的 `Iter2` 类型遍历两个值的序列,例如 `Map`。任何具有方法 " +"`.iter2() : Iter2[A, B]` 的类型都可以使用两个循环变量的 `for .. in` 进行遍历:" #: ../../language/fundamentals.md:729 msgid "" @@ -3027,7 +3052,7 @@ msgstr "" msgid "" "Another example of `for .. in` with two loop variables is traversing an " "array while keeping track of array index:" -msgstr "" +msgstr "另一个使用两个循环变量的 `for .. in` 的示例是在遍历数组时跟踪数组索引:" #: ../../language/fundamentals.md:738 msgid "" @@ -3050,7 +3075,7 @@ msgstr "" msgid "" "Control flow operations such as `return`, `break` and error handling are " "supported in the body of `for .. in` loop:" -msgstr "" +msgstr "`for .. in` 循环的主体支持诸如 `return`、`break` 和错误处理等控制流操作:" #: ../../language/fundamentals.md:752 msgid "" @@ -3076,17 +3101,17 @@ msgstr "" #: ../../language/fundamentals.md:764 msgid "If a loop variable is unused, it can be ignored with `_`." -msgstr "" +msgstr "如果循环变量未使用,可以使用 `_` 忽略它。" #: ../../language/fundamentals.md:766 msgid "Functional loop" -msgstr "" +msgstr "函数式循环" #: ../../language/fundamentals.md:768 msgid "" "Functional loop is a powerful feature in MoonBit that enables you to " "write loops in a functional style." -msgstr "" +msgstr "函数式循环是 MoonBit 中的一个强大功能,它使您可以以函数式风格编写循环。" #: ../../language/fundamentals.md:770 msgid "" @@ -3101,6 +3126,10 @@ msgid "" "keyword can be omitted if the value is the last expression in the loop " "body." msgstr "" +"函数式循环接收参数并返回一个值。它使用 `loop` " +"关键字定义,后跟其参数和循环体。循环体是一系列子句,每个子句由模式和表达式组成。与输入匹配的模式的子句将会被执行,并且循环将返回表达式的值。如果没有对应的模式,程序会中止。使用" +" `continue` 关键字和参数进入循环的下一次迭代。使用 `break` " +"关键字和参数从循环中返回一个值。如果值是循环体中的最后一个表达式,则可以省略 `break` 关键字。" #: ../../language/fundamentals.md:772 msgid "" @@ -3120,11 +3149,11 @@ msgstr "" msgid "" "Currently in `loop exprs { ... }`, `exprs` is nonempty list, while `for {" " ... }` is accepted for infinite loop." -msgstr "" +msgstr "目前在 `loop exprs { ... }` 中,`exprs` 是非空列表,而 `for { ... }` 用于无限循环。" #: ../../language/fundamentals.md:782 msgid "Iterator" -msgstr "" +msgstr "迭代器" #: ../../language/fundamentals.md:784 msgid "" @@ -3137,21 +3166,26 @@ msgid "" "the sequence. The former is called _external iterator_ (visible to user) " "and the latter is called _internal iterator_ (invisible to user)." msgstr "" +"迭代器是一个对象,它在遍历序列的同时提供对其元素的访问。传统的面向对象语言如 Java 的 `Iterator` 使用 `next()` " +"`hasNext()` 来遍历迭代过程,而函数式语言(JavaScript 的 `forEach`,Lisp 的 " +"`mapcar`)提供了一个高阶函数,该函数接受一个操作和一个序列,然后使用该操作应用于序列。前者称为_外部迭代器_(对用户可见),后者称为_内部迭代器_(对用户不可见)。" #: ../../language/fundamentals.md:792 msgid "" "The built-in type `Iter[T]` is MoonBit's internal iterator " "implementation. Almost all built-in sequential data structures have " "implemented `Iter`:" -msgstr "" +msgstr "内置类型 `Iter[T]` 是 MoonBit 的内部迭代器实现。几乎所有内置的顺序数据结构都已经实现了 `Iter`:" #: ../../language/fundamentals.md:795 msgid "" +"///|\n" "fn filter_even(l : Array[Int]) -> Array[Int] {\n" " let l_iter : Iter[Int] = l.iter()\n" " l_iter.filter(fn { x => (x & 1) == 0 }).collect()\n" "}\n" "\n" +"///|\n" "fn fact(n : Int) -> Int {\n" " let start = 1\n" " let range : Iter[Int] = start.until(n)\n" @@ -3161,41 +3195,41 @@ msgstr "" #: ../../language/fundamentals.md:801 msgid "Commonly used methods include:" -msgstr "" +msgstr "常用的方法包括:" #: ../../language/fundamentals.md:803 msgid "" "`each`: Iterates over each element in the iterator, applying some " "function to each element." -msgstr "" +msgstr "`each`: 遍历迭代器中的每个元素,对每个元素应用某个函数。" #: ../../language/fundamentals.md:804 msgid "" "`fold`: Folds the elements of the iterator using the given function, " "starting with the given initial value." -msgstr "" +msgstr "`fold`: 使用给定的函数,从给定的初始值开始,对迭代器的元素进行“折叠”。" #: ../../language/fundamentals.md:805 msgid "`collect`: Collects the elements of the iterator into an array." -msgstr "" +msgstr "`collect`: 将迭代器的元素收集到一个数组中。" #: ../../language/fundamentals.md:807 msgid "" "`filter`: _lazy_ Filters the elements of the iterator based on a " "predicate function." -msgstr "" +msgstr "`filter`: (惰性)根据谓词函数过滤迭代器的元素。" #: ../../language/fundamentals.md:808 msgid "" "`map`: _lazy_ Transforms the elements of the iterator using a mapping " "function." -msgstr "" +msgstr "`map`: (惰性)使用映射函数转换迭代器的元素。" #: ../../language/fundamentals.md:809 msgid "" "`concat`: _lazy_ Combines two iterators into one by appending the " "elements of the second iterator to the first." -msgstr "" +msgstr "`concat`: (惰性)通过将第二个迭代器的元素附加到第一个迭代器,将两个迭代器合并为一个。" #: ../../language/fundamentals.md:811 msgid "" @@ -3207,6 +3241,9 @@ msgid "" "sequence: no extra cost. MoonBit encourages user to pass an `Iter` across" " functions instead of the sequence object itself." msgstr "" +"像 `filter` `map` 这样的方法在序列对象(例如 Array)上非常常见。但是,`Iter` 的不同之处在于,任何构造新 `Iter`" +" 的方法都是**惰性**的(即在调用时不会开始迭代,因为它被包装在一个函数内),因此不会为中间值分配内存。这就是使 `Iter` " +"优于遍历序列的原因:没有额外的成本。MoonBit 鼓励用户将 `Iter` 传递给函数,而不是传递序列对象本身。" #: ../../language/fundamentals.md:819 msgid "" @@ -3216,21 +3253,21 @@ msgid "" "`Iter`, namely, a function that returns an `Iter[S]`. Take `Bytes` as an " "example:" msgstr "" +"预定义的序列结构如 `Array` 及其迭代器应该足够使用。但是,为了在自定义序列(元素类型为 `S`)中使用这些方法,我们需要实现 " +"`Iter`,即返回 `Iter[S]` 的函数。以 `Bytes` 为例:" #: ../../language/fundamentals.md:824 msgid "" +"///|\n" "fn iter(data : Bytes) -> Iter[Byte] {\n" -" Iter::new(\n" -" fn(visit : (Byte) -> IterResult) -> IterResult {\n" -" for byte in data {\n" -" if visit(byte) == IterEnd {\n" -" break IterEnd\n" -" }\n" -" } else {\n" -" IterContinue\n" -" }\n" -" },\n" -" )\n" +" Iter::new(fn(visit : (Byte) -> IterResult) -> IterResult {\n" +" for byte in data {\n" +" guard let IterContinue = visit(byte) else { x => break x }\n" +"\n" +" } else {\n" +" IterContinue\n" +" }\n" +" })\n" "}\n" msgstr "" @@ -3239,11 +3276,11 @@ msgid "" "Almost all `Iter` implementations are identical to that of `Bytes`, the " "only main difference being the code block that actually does the " "iteration." -msgstr "" +msgstr "几乎所有 `Iter` 实现都与 `Bytes` 的实现相同,唯一的主要区别是实际执行迭代的代码块。" #: ../../language/fundamentals.md:833 msgid "Implementation details" -msgstr "" +msgstr "实现细节" #: ../../language/fundamentals.md:835 msgid "" @@ -3252,16 +3289,18 @@ msgid "" "`IterResult` is an enum object that tracks the state of current iteration" " which consists any of the 2 states:" msgstr "" +"类型 `Iter[T]` 基本上是 `((T) -> IterResult) -> IterResult` " +"的类型别名,它是一个高阶函数,接受一个操作,`IterResult` 是一个枚举对象,用于跟踪当前迭代的状态,包含以下 2 种状态:" #: ../../language/fundamentals.md:840 msgid "`IterEnd`: marking the end of an iteration" -msgstr "" +msgstr "`IterEnd`: 标记迭代结束" #: ../../language/fundamentals.md:841 msgid "" "`IterContinue`: marking the end of an iteration is yet to be reached, " "implying the iteration will still continue at this state." -msgstr "" +msgstr "`IterContinue`: 标记迭代结束尚未到达,暗示迭代将在此状态继续。" #: ../../language/fundamentals.md:843 msgid "" @@ -3270,20 +3309,22 @@ msgid "" "Whether that state being `IterEnd` `IterContinue` depends on the " "function." msgstr "" +"简单来说,`Iter[T]` 接受一个函数 `(T) -> IterResult` 并使用它将 `Iter[T]` 本身转换为类型为 " +"`IterResult` 的新状态。" #: ../../language/fundamentals.md:847 msgid "" "Iterator provides a unified way to iterate through data structures, and " "they can be constructed at basically no cost: as long as `fn(yield)` " "doesn't execute, the iteration process doesn't start." -msgstr "" +msgstr "迭代器提供了一种统一的遍历数据结构的方式,它们基本上可以无成本地构建:只要 `fn(yield)` 不执行,迭代过程就不会开始。" #: ../../language/fundamentals.md:851 msgid "" "Internally a `Iter::run()` is used to trigger the iteration. Chaining all" " sorts of `Iter` methods might be visually pleasing, but do notice the " "heavy work underneath the abstraction." -msgstr "" +msgstr "`Iter::run()` 在在内部触发迭代。链接各种 `Iter` 方法可能看起来很美观,但请注意抽象层下面的繁重工作。" #: ../../language/fundamentals.md:855 msgid "" @@ -3293,6 +3334,8 @@ msgid "" "operation but actually has linear time complexity. Carefully use " "iterators or performance issue might occur." msgstr "" +"因此,与外部迭代器不同,一旦迭代开始,除非到达末尾,否则无法停止。诸如 `count()` 这样的方法,它计算迭代器中元素的数量看起来像是一个 " +"`O(1)` 操作,但实际上具有线性时间复杂度。请谨慎使用迭代器,否则可能会出现性能问题。" #: ../../language/fundamentals.md:861 msgid "Custom Data Types" @@ -4368,87 +4411,87 @@ msgid "" " let x = 1\n" " //! x + 1\n" " x + 2\n" -"}\n" +"}" msgstr "" -#: ../../language/introduction.md:20 +#: ../../language/introduction.md:28 msgid "Expressions include:" msgstr "表达式包括:" -#: ../../language/introduction.md:22 +#: ../../language/introduction.md:30 msgid "" "Value literals (e.g. Boolean values, numbers, characters, strings, " "arrays, tuples, structs)" msgstr "值字面量(例如布尔值、数字、字符、字符串、数组、元组、结构体)" -#: ../../language/introduction.md:23 +#: ../../language/introduction.md:31 msgid "Arithmetical, logical, or comparison operations" msgstr "算术、逻辑或比较操作" -#: ../../language/introduction.md:24 +#: ../../language/introduction.md:32 msgid "" "Accesses to array elements (e.g. `a[0]`), struct fields (e.g `r.x`), " "tuple components (e.g. `t.0`), etc." msgstr "访问数组元素(例如 `a[0]`),结构体字段(例如 `r.x`),元组组件(例如 `t.0`)等。" -#: ../../language/introduction.md:25 +#: ../../language/introduction.md:33 msgid "Variables and (capitalized) enum constructors" msgstr "变量和枚举构造函数" -#: ../../language/introduction.md:26 +#: ../../language/introduction.md:34 msgid "Anonymous local function definitions" msgstr "匿名本地函数定义" -#: ../../language/introduction.md:27 +#: ../../language/introduction.md:35 msgid "`match`, `if`, `loop` expressions, etc." msgstr "`match`,`if`,`loop` 表达式等。" -#: ../../language/introduction.md:29 +#: ../../language/introduction.md:37 msgid "Statements include:" msgstr "语句包括:" -#: ../../language/introduction.md:31 +#: ../../language/introduction.md:39 msgid "Named local function definitions" msgstr "命名本地函数定义" -#: ../../language/introduction.md:32 +#: ../../language/introduction.md:40 msgid "Local variable bindings" msgstr "本地变量绑定" -#: ../../language/introduction.md:33 +#: ../../language/introduction.md:41 msgid "Assignments" msgstr "赋值" -#: ../../language/introduction.md:34 +#: ../../language/introduction.md:42 msgid "`return` statements" msgstr "`return` 语句" -#: ../../language/introduction.md:35 +#: ../../language/introduction.md:43 msgid "Any expression whose return type is `Unit`, (e.g. `ignore`)" msgstr "任何返回类型为 `Unit` 的表达式(例如 `ignore`)" -#: ../../language/introduction.md:37 +#: ../../language/introduction.md:45 msgid "" "A code block can contain multiple statements and one expression, and the " "value of the expression is the value of the code block." msgstr "代码块可以包含多个语句和一个表达式,表达式的值是代码块的值。" -#: ../../language/introduction.md:39 +#: ../../language/introduction.md:47 msgid "Variable Binding" msgstr "变量绑定" -#: ../../language/introduction.md:41 +#: ../../language/introduction.md:49 msgid "" "A variable can be declared as mutable or immutable using `let mut` or " "`let`, respectively. A mutable variable can be reassigned to a new value," " while an immutable one cannot." msgstr "变量可以使用 `let mut` 或 `let` 声明为可变或不可变。可变变量可以重新赋值为新值,而不可变变量则不能。" -#: ../../language/introduction.md:43 +#: ../../language/introduction.md:51 msgid "A constant can only be declared at top level and cannot be changed." msgstr "常量只能在顶层声明,不能更改。" -#: ../../language/introduction.md:45 +#: ../../language/introduction.md:53 msgid "" "let zero = 0\n" "\n" @@ -4459,28 +4502,28 @@ msgid "" " let mut i = 10\n" " i = 20\n" " println(i + zero + ZERO)\n" -"}\n" +"}" msgstr "" -#: ../../language/introduction.md:50 +#: ../../language/introduction.md:68 msgid "A top level variable binding" msgstr "顶层变量绑定" -#: ../../language/introduction.md:51 +#: ../../language/introduction.md:69 msgid "" "requires **explicit** type annotation (unless defined using literals such" " as string, byte or numbers)" msgstr "需要 **显式** 类型注释(除非使用字符串、字节或数字等字面量定义)" -#: ../../language/introduction.md:52 +#: ../../language/introduction.md:70 msgid "can't be mutable (use `Ref` instead)" msgstr "不能是可变的(使用 `Ref` 代替)" -#: ../../language/introduction.md:56 +#: ../../language/introduction.md:74 msgid "Naming conventions" msgstr "命名约定" -#: ../../language/introduction.md:58 +#: ../../language/introduction.md:76 msgid "" "Variables, functions should start with lowercase letters `a-z` and can " "contain letters, numbers, underscore, and other non-ascii unicode chars. " @@ -4489,7 +4532,7 @@ msgstr "" "变量、函数应以小写字母 `a-z` 开头,可以包含字母、数字、下划线和其他非 ASCII 的 Unicode 字符。建议使用 snake_case" " 命名。" -#: ../../language/introduction.md:61 +#: ../../language/introduction.md:79 msgid "" "Constants, types should start with uppercase letters `A-Z` and can " "contain letters, numbers, underscore, and other non-ascii unicode chars. " @@ -4498,29 +4541,29 @@ msgstr "" "常量、类型应以大写字母 `A-Z` 开头,可以包含字母、数字、下划线和其他非 ASCII 的 Unicode 字符。建议使用 PascalCase" " 或 SCREAMING_SNAKE_CASE 命名。" -#: ../../language/introduction.md:64 +#: ../../language/introduction.md:82 msgid "Program entrance" msgstr "程序入口" -#: ../../language/introduction.md:66 +#: ../../language/introduction.md:84 msgid "`init` and `main`" msgstr "`init` 和 `main`" -#: ../../language/introduction.md:67 +#: ../../language/introduction.md:85 msgid "" "There is a specialized function called `init` function. The `init` " "function is special:" msgstr "有一个专门的函数称为 `init` 函数。`init` 函数是特殊的:" -#: ../../language/introduction.md:69 +#: ../../language/introduction.md:87 msgid "It has no parameter list nor return type." msgstr "它没有参数列表也没有返回类型。" -#: ../../language/introduction.md:70 +#: ../../language/introduction.md:88 msgid "There can be multiple `init` functions in the same package." msgstr "同一个包中可以有多个 `init` 函数。" -#: ../../language/introduction.md:71 +#: ../../language/introduction.md:89 msgid "" "An `init` function can't be explicitly called or referred to by other " "functions. Instead, all `init` functions will be implicitly called when " @@ -4528,71 +4571,71 @@ msgid "" "of statements." msgstr "`init` 函数不能被显式调用或被其他函数引用。相反,所有 `init` 函数将在初始化包时隐式调用。因此,`init` 函数应该只包含语句。" -#: ../../language/introduction.md:74 +#: ../../language/introduction.md:92 msgid "" "fn init {\n" " let x = 1\n" " println(x)\n" -"}\n" +"}" msgstr "" -#: ../../language/introduction.md:80 +#: ../../language/introduction.md:100 msgid "" "There is another specialized function called `main` function. The `main` " "function is the main entrance of the program, and it will be executed " "after the initialization stage." msgstr "还有另一个专门的函数称为 `main` 函数。`main` 函数是程序的主入口,它将在初始化阶段之后执行。" -#: ../../language/introduction.md:82 +#: ../../language/introduction.md:102 msgid "Same as the `init` function, it has no parameter list nor return type." msgstr "与 `init` 函数相同,它没有参数列表也没有返回类型。" -#: ../../language/introduction.md:84 +#: ../../language/introduction.md:104 msgid "" "fn main {\n" " let x = 2\n" " println(x)\n" -"}\n" +"}" msgstr "" -#: ../../language/introduction.md:90 +#: ../../language/introduction.md:112 msgid "The previous two code snippets will print the following at runtime:" msgstr "前两个代码片段将在运行时打印以下内容:" -#: ../../language/introduction.md:92 +#: ../../language/introduction.md:114 msgid "" "1\n" "2\n" msgstr "" -#: ../../language/introduction.md:97 +#: ../../language/introduction.md:119 msgid "" "Only packages that are `main` packages can define such `main` function. " "Check out [build system tutorial](/toolchain/moon/tutorial) for detail." msgstr "只有 `main` 包的包才能定义这样的 `main` 函数。查看[构建系统教程](/toolchain/moon/tutorial)了解详情。" -#: ../../language/introduction.md:99 +#: ../../language/introduction.md:121 msgid "moon.pkg.json" msgstr "" -#: ../../language/introduction.md:99 +#: ../../language/introduction.md:121 msgid "" "{\n" " \"is-main\": true\n" "}" msgstr "" -#: ../../language/introduction.md:104 +#: ../../language/introduction.md:126 msgid "`test`" msgstr "" -#: ../../language/introduction.md:106 +#: ../../language/introduction.md:128 msgid "" "There's also a top-level structure called `test` block. A `test` block " "defines inline tests, such as:" msgstr "还有一个称为 `test` 块的顶级结构。`test` 块定义内联测试,例如:" -#: ../../language/introduction.md:108 ../../language/tests.md:11 +#: ../../language/introduction.md:130 ../../language/tests.md:11 msgid "" "test \"test_name\" {\n" " assert_eq!(1 + 1, 2)\n" @@ -4601,7 +4644,7 @@ msgid "" "}\n" msgstr "" -#: ../../language/introduction.md:114 +#: ../../language/introduction.md:136 msgid "" "The following contents will use `test` block and `main` function to " "demonstrate the execution result, and we assume that all the `test` " @@ -6105,6 +6148,5 @@ msgid "" " packages defined in the `import` and `test-import` sections of the " "package configuration (`moon.pkg.json`)." msgstr "" -"黑盒测试文件(`_test.mbt`)导入当前包和包配置(`moon.pkg.json`)中的 `import` 和 " -"`test-import` 部分定义的包。" - +"黑盒测试文件(`_test.mbt`)导入当前包和包配置(`moon.pkg.json`)中的 `import` 和 `test-import` " +"部分定义的包。" \ No newline at end of file diff --git a/next/sources/language/src/iter/top.mbt b/next/sources/language/src/iter/top.mbt index 8d970c17..f6addaeb 100644 --- a/next/sources/language/src/iter/top.mbt +++ b/next/sources/language/src/iter/top.mbt @@ -1,9 +1,11 @@ // start iter 1 +///| fn filter_even(l : Array[Int]) -> Array[Int] { let l_iter : Iter[Int] = l.iter() l_iter.filter(fn { x => (x & 1) == 0 }).collect() } +///| fn fact(n : Int) -> Int { let start = 1 let range : Iter[Int] = start.until(n) @@ -12,17 +14,15 @@ fn fact(n : Int) -> Int { // end iter 1 // start iter 2 +///| fn iter(data : Bytes) -> Iter[Byte] { - Iter::new( - fn(visit : (Byte) -> IterResult) -> IterResult { - for byte in data { - if visit(byte) == IterEnd { - break IterEnd - } - } else { - IterContinue - } - }, - ) + Iter::new(fn(visit : (Byte) -> IterResult) -> IterResult { + for byte in data { + guard let IterContinue = visit(byte) else { x => break x } + + } else { + IterContinue + } + }) } // end iter 2