diff options
author | Li Jin <dragon-fly@qq.com> | 2023-10-31 16:06:05 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-10-31 16:06:18 +0800 |
commit | 2dc090daf42d9449b2c63e7167084092d0bd13ac (patch) | |
tree | 89ce76c2f25ab5d6ec020ad91b91efe010ddcbce /doc/docs/zh | |
parent | 630fef5a40d2f7a221b9c3752462c8780eb17af4 (diff) | |
download | yuescript-2dc090daf42d9449b2c63e7167084092d0bd13ac.tar.gz yuescript-2dc090daf42d9449b2c63e7167084092d0bd13ac.tar.bz2 yuescript-2dc090daf42d9449b2c63e7167084092d0bd13ac.zip |
fix doc. add busted to testing work.
Diffstat (limited to 'doc/docs/zh')
-rwxr-xr-x | doc/docs/zh/doc/README.md | 106 |
1 files changed, 53 insertions, 53 deletions
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 340498b..69f5e68 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md | |||
@@ -30,7 +30,7 @@ inventory = | |||
30 | count: 3 | 30 | count: 3 |
31 | 31 | ||
32 | -- 管道操作符 | 32 | -- 管道操作符 |
33 | {1, 2, 3} | 33 | [1, 2, 3] |
34 | |> map (x)-> x * 2 | 34 | |> map (x)-> x * 2 |
35 | |> filter (x)-> x > 4 | 35 | |> filter (x)-> x > 4 |
36 | |> reduce 0, (a, b)-> a + b | 36 | |> reduce 0, (a, b)-> a + b |
@@ -62,7 +62,7 @@ inventory = | |||
62 | count: 3 | 62 | count: 3 |
63 | 63 | ||
64 | -- 管道操作符 | 64 | -- 管道操作符 |
65 | {1, 2, 3} | 65 | [1, 2, 3] |
66 | |> map (x)-> x * 2 | 66 | |> map (x)-> x * 2 |
67 | |> filter (x)-> x > 4 | 67 | |> filter (x)-> x > 4 |
68 | |> reduce 0, (a, b)-> a + b | 68 | |> reduce 0, (a, b)-> a + b |
@@ -336,7 +336,7 @@ import "utils" as { | |||
336 | $, -- 表示导入所有宏的符号 | 336 | $, -- 表示导入所有宏的符号 |
337 | $foreach: $each -- 重命名宏 $foreach 为 $each | 337 | $foreach: $each -- 重命名宏 $foreach 为 $each |
338 | } | 338 | } |
339 | {1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 339 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
340 | ``` | 340 | ``` |
341 | <YueDisplay> | 341 | <YueDisplay> |
342 | <pre> | 342 | <pre> |
@@ -352,7 +352,7 @@ import "utils" as { | |||
352 | $, -- 表示导入所有宏的符号 | 352 | $, -- 表示导入所有宏的符号 |
353 | $foreach: $each -- 重命名宏 $foreach 为 $each | 353 | $foreach: $each -- 重命名宏 $foreach 为 $each |
354 | } | 354 | } |
355 | {1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ | 355 | [1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ |
356 | ]] | 356 | ]] |
357 | </pre> | 357 | </pre> |
358 | </YueDisplay> | 358 | </YueDisplay> |
@@ -465,12 +465,12 @@ print v(1) > v(2) <= v(3) | |||
465 | **[] =** 操作符用于向Lua表的最后插入值。 | 465 | **[] =** 操作符用于向Lua表的最后插入值。 |
466 | 466 | ||
467 | ```moonscript | 467 | ```moonscript |
468 | tab = {} | 468 | tab = [] |
469 | tab[] = "Value" | 469 | tab[] = "Value" |
470 | ``` | 470 | ``` |
471 | <YueDisplay> | 471 | <YueDisplay> |
472 | <pre> | 472 | <pre> |
473 | tab = {} | 473 | tab = [] |
474 | tab[] = "Value" | 474 | tab[] = "Value" |
475 | </pre> | 475 | </pre> |
476 | </YueDisplay> | 476 | </YueDisplay> |
@@ -1104,27 +1104,27 @@ print hello, the_day | |||
1104 | 1104 | ||
1105 | ```moonscript | 1105 | ```moonscript |
1106 | obj2 = { | 1106 | obj2 = { |
1107 | numbers: {1,2,3,4} | 1107 | numbers: [1,2,3,4] |
1108 | properties: { | 1108 | properties: { |
1109 | color: "green" | 1109 | color: "green" |
1110 | height: 13.5 | 1110 | height: 13.5 |
1111 | } | 1111 | } |
1112 | } | 1112 | } |
1113 | 1113 | ||
1114 | {numbers: {first, second}} = obj2 | 1114 | {numbers: [first, second]} = obj2 |
1115 | print first, second, color | 1115 | print first, second, color |
1116 | ``` | 1116 | ``` |
1117 | <YueDisplay> | 1117 | <YueDisplay> |
1118 | <pre> | 1118 | <pre> |
1119 | obj2 = { | 1119 | obj2 = { |
1120 | numbers: {1,2,3,4} | 1120 | numbers: [1,2,3,4] |
1121 | properties: { | 1121 | properties: { |
1122 | color: "green" | 1122 | color: "green" |
1123 | height: 13.5 | 1123 | height: 13.5 |
1124 | } | 1124 | } |
1125 | } | 1125 | } |
1126 | 1126 | ||
1127 | {numbers: {first, second}} = obj2 | 1127 | {numbers: [first, second]} = obj2 |
1128 | print first, second, color | 1128 | print first, second, color |
1129 | </pre> | 1129 | </pre> |
1130 | </YueDisplay> | 1130 | </YueDisplay> |
@@ -1133,7 +1133,7 @@ print first, second, color | |||
1133 | 1133 | ||
1134 | ```moonscript | 1134 | ```moonscript |
1135 | { | 1135 | { |
1136 | numbers: {first, second} | 1136 | numbers: [first, second] |
1137 | properties: { | 1137 | properties: { |
1138 | color: color | 1138 | color: color |
1139 | } | 1139 | } |
@@ -1142,7 +1142,7 @@ print first, second, color | |||
1142 | <YueDisplay> | 1142 | <YueDisplay> |
1143 | <pre> | 1143 | <pre> |
1144 | { | 1144 | { |
1145 | numbers: {first, second} | 1145 | numbers: [first, second] |
1146 | properties: { | 1146 | properties: { |
1147 | color: color | 1147 | color: color |
1148 | } | 1148 | } |
@@ -1186,7 +1186,7 @@ print first, second, color | |||
1186 | 在进行列表解构时,您可以使用`_`作为占位符: | 1186 | 在进行列表解构时,您可以使用`_`作为占位符: |
1187 | 1187 | ||
1188 | ```moonscript | 1188 | ```moonscript |
1189 | {_, two, _, four} = items | 1189 | [_, two, _, four] = items |
1190 | ``` | 1190 | ``` |
1191 | <YueDisplay> | 1191 | <YueDisplay> |
1192 | <pre> | 1192 | <pre> |
@@ -1199,22 +1199,22 @@ print first, second, color | |||
1199 | 解构也可以出现在其它隐式进行赋值的地方。一个例子是用在for循环: | 1199 | 解构也可以出现在其它隐式进行赋值的地方。一个例子是用在for循环: |
1200 | 1200 | ||
1201 | ```moonscript | 1201 | ```moonscript |
1202 | tuples = { | 1202 | tuples = [ |
1203 | {"hello", "world"} | 1203 | ["hello", "world"] |
1204 | {"egg", "head"} | 1204 | ["egg", "head"] |
1205 | } | 1205 | ] |
1206 | 1206 | ||
1207 | for {left, right} in *tuples | 1207 | for [left, right] in *tuples |
1208 | print left, right | 1208 | print left, right |
1209 | ``` | 1209 | ``` |
1210 | <YueDisplay> | 1210 | <YueDisplay> |
1211 | <pre> | 1211 | <pre> |
1212 | tuples = { | 1212 | tuples = [ |
1213 | {"hello", "world"} | 1213 | ["hello", "world"] |
1214 | {"egg", "head"} | 1214 | ["egg", "head"] |
1215 | } | 1215 | ] |
1216 | 1216 | ||
1217 | for {left, right} in *tuples | 1217 | for [left, right] in *tuples |
1218 | print left, right | 1218 | print left, right |
1219 | </pre> | 1219 | </pre> |
1220 | </YueDisplay> | 1220 | </YueDisplay> |
@@ -1273,7 +1273,7 @@ print "好的" | |||
1273 | 1273 | ||
1274 | 您可以将函数返回的结果赋值给一个可变参数符号 `...`。然后使用Lua的方式访问其内容。 | 1274 | 您可以将函数返回的结果赋值给一个可变参数符号 `...`。然后使用Lua的方式访问其内容。 |
1275 | ```moonscript | 1275 | ```moonscript |
1276 | list = {1, 2, 3, 4, 5} | 1276 | list = [1, 2, 3, 4, 5] |
1277 | fn = (ok) -> ok, table.unpack list | 1277 | fn = (ok) -> ok, table.unpack list |
1278 | ok, ... = fn true | 1278 | ok, ... = fn true |
1279 | count = select '#', ... | 1279 | count = select '#', ... |
@@ -1282,7 +1282,7 @@ print ok, count, first | |||
1282 | ``` | 1282 | ``` |
1283 | <YueDisplay> | 1283 | <YueDisplay> |
1284 | <pre> | 1284 | <pre> |
1285 | list = {1, 2, 3, 4, 5} | 1285 | list = [1, 2, 3, 4, 5] |
1286 | fn = (ok) -> ok, table.unpack list | 1286 | fn = (ok) -> ok, table.unpack list |
1287 | ok, ... = fn true | 1287 | ok, ... = fn true |
1288 | count = select '#', ... | 1288 | count = select '#', ... |
@@ -1691,36 +1691,36 @@ my_func 5, 6, 7, | |||
1691 | 因为Lua表也使用逗号作为分隔符,这种缩进语法有助于让值成为参数列表的一部分,而不是Lua表的一部分。 | 1691 | 因为Lua表也使用逗号作为分隔符,这种缩进语法有助于让值成为参数列表的一部分,而不是Lua表的一部分。 |
1692 | 1692 | ||
1693 | ```moonscript | 1693 | ```moonscript |
1694 | x = { | 1694 | x = [ |
1695 | 1, 2, 3, 4, a_func 4, 5, | 1695 | 1, 2, 3, 4, a_func 4, 5, |
1696 | 5, 6, | 1696 | 5, 6, |
1697 | 8, 9, 10 | 1697 | 8, 9, 10 |
1698 | } | 1698 | ] |
1699 | ``` | 1699 | ``` |
1700 | <YueDisplay> | 1700 | <YueDisplay> |
1701 | <pre> | 1701 | <pre> |
1702 | x = { | 1702 | x = [ |
1703 | 1, 2, 3, 4, a_func 4, 5, | 1703 | 1, 2, 3, 4, a_func 4, 5, |
1704 | 5, 6, | 1704 | 5, 6, |
1705 | 8, 9, 10 | 1705 | 8, 9, 10 |
1706 | } | 1706 | ] |
1707 | </pre> | 1707 | </pre> |
1708 | </YueDisplay> | 1708 | </YueDisplay> |
1709 | 1709 | ||
1710 | 有个不常见的写法可以注意一下,如果我们将在后面使用较低的缩进,我们可以为函数参数提供更深的缩进来区分列表的归属。 | 1710 | 有个不常见的写法可以注意一下,如果我们将在后面使用较低的缩进,我们可以为函数参数提供更深的缩进来区分列表的归属。 |
1711 | 1711 | ||
1712 | ```moonscript | 1712 | ```moonscript |
1713 | y = { my_func 1, 2, 3, | 1713 | y = [ my_func 1, 2, 3, |
1714 | 4, 5, | 1714 | 4, 5, |
1715 | 5, 6, 7 | 1715 | 5, 6, 7 |
1716 | } | 1716 | ] |
1717 | ``` | 1717 | ``` |
1718 | <YueDisplay> | 1718 | <YueDisplay> |
1719 | <pre> | 1719 | <pre> |
1720 | y = { my_func 1, 2, 3, | 1720 | y = [ my_func 1, 2, 3, |
1721 | 4, 5, | 1721 | 4, 5, |
1722 | 5, 6, 7 | 1722 | 5, 6, 7 |
1723 | } | 1723 | ] |
1724 | </pre> | 1724 | </pre> |
1725 | </YueDisplay> | 1725 | </YueDisplay> |
1726 | 1726 | ||
@@ -1786,12 +1786,12 @@ print @value | |||
1786 | 您可以通过一个占位符指定回调函数的传参位置。 | 1786 | 您可以通过一个占位符指定回调函数的传参位置。 |
1787 | 1787 | ||
1788 | ```moonscript | 1788 | ```moonscript |
1789 | (x) <- map _, {1, 2, 3} | 1789 | (x) <- map _, [1, 2, 3] |
1790 | x * 2 | 1790 | x * 2 |
1791 | ``` | 1791 | ``` |
1792 | <YueDisplay> | 1792 | <YueDisplay> |
1793 | <pre> | 1793 | <pre> |
1794 | (x) <- map _, {1, 2, 3} | 1794 | (x) <- map _, [1, 2, 3] |
1795 | x * 2 | 1795 | x * 2 |
1796 | </pre> | 1796 | </pre> |
1797 | </YueDisplay> | 1797 | </YueDisplay> |
@@ -1822,11 +1822,11 @@ print result, msg | |||
1822 | 和Lua一样,表格可以通过花括号进行定义。 | 1822 | 和Lua一样,表格可以通过花括号进行定义。 |
1823 | 1823 | ||
1824 | ```moonscript | 1824 | ```moonscript |
1825 | some_values = { 1, 2, 3, 4 } | 1825 | some_values = [1, 2, 3, 4] |
1826 | ``` | 1826 | ``` |
1827 | <YueDisplay> | 1827 | <YueDisplay> |
1828 | <pre> | 1828 | <pre> |
1829 | some_values = { 1, 2, 3, 4 } | 1829 | some_values = [1, 2, 3, 4] |
1830 | </pre> | 1830 | </pre> |
1831 | </YueDisplay> | 1831 | </YueDisplay> |
1832 | 1832 | ||
@@ -1855,14 +1855,14 @@ some_values = { | |||
1855 | profile = | 1855 | profile = |
1856 | height: "4英尺", | 1856 | height: "4英尺", |
1857 | shoe_size: 13, | 1857 | shoe_size: 13, |
1858 | favorite_foods: {"冰淇淋", "甜甜圈"} | 1858 | favorite_foods: ["冰淇淋", "甜甜圈"] |
1859 | ``` | 1859 | ``` |
1860 | <YueDisplay> | 1860 | <YueDisplay> |
1861 | <pre> | 1861 | <pre> |
1862 | profile = | 1862 | profile = |
1863 | height: "4英尺", | 1863 | height: "4英尺", |
1864 | shoe_size: 13, | 1864 | shoe_size: 13, |
1865 | favorite_foods: {"冰淇淋", "甜甜圈"} | 1865 | favorite_foods: ["冰淇淋", "甜甜圈"] |
1866 | </pre> | 1866 | </pre> |
1867 | </YueDisplay> | 1867 | </YueDisplay> |
1868 | 1868 | ||
@@ -1977,12 +1977,12 @@ list_with_one_element = [ 1, ] | |||
1977 | 以下操作创建了一个items表的副本,但所有包含的值都翻倍了。 | 1977 | 以下操作创建了一个items表的副本,但所有包含的值都翻倍了。 |
1978 | 1978 | ||
1979 | ```moonscript | 1979 | ```moonscript |
1980 | items = [ 1, 2, 3, 4 ] | 1980 | items = [1, 2, 3, 4] |
1981 | doubled = [item * 2 for i, item in ipairs items] | 1981 | doubled = [item * 2 for i, item in ipairs items] |
1982 | ``` | 1982 | ``` |
1983 | <YueDisplay> | 1983 | <YueDisplay> |
1984 | <pre> | 1984 | <pre> |
1985 | items = [ 1, 2, 3, 4 ] | 1985 | items = [1, 2, 3, 4] |
1986 | doubled = [item * 2 for i, item in ipairs items] | 1986 | doubled = [item * 2 for i, item in ipairs items] |
1987 | </pre> | 1987 | </pre> |
1988 | </YueDisplay> | 1988 | </YueDisplay> |
@@ -2097,12 +2097,12 @@ sqrts = {i, math.sqrt i for i in *numbers} | |||
2097 | 在下面的示例中,我们将一些数组转换为一个表,其中每个数组里的第一项是键,第二项是值。 | 2097 | 在下面的示例中,我们将一些数组转换为一个表,其中每个数组里的第一项是键,第二项是值。 |
2098 | 2098 | ||
2099 | ```moonscript | 2099 | ```moonscript |
2100 | tuples = {{"hello", "world"}, {"foo", "bar"}} | 2100 | tuples = [ ["hello", "world"], ["foo", "bar"]] |
2101 | tbl = {unpack tuple for tuple in *tuples} | 2101 | tbl = {unpack tuple for tuple in *tuples} |
2102 | ``` | 2102 | ``` |
2103 | <YueDisplay> | 2103 | <YueDisplay> |
2104 | <pre> | 2104 | <pre> |
2105 | tuples = { {"hello", "world"}, {"foo", "bar"} } | 2105 | tuples = [ ["hello", "world"], ["foo", "bar"]] |
2106 | tbl = {unpack tuple for tuple in *tuples} | 2106 | tbl = {unpack tuple for tuple in *tuples} |
2107 | </pre> | 2107 | </pre> |
2108 | </YueDisplay> | 2108 | </YueDisplay> |
@@ -2332,14 +2332,14 @@ while i < 10 | |||
2332 | 继续语句也可以与各种循环表达式一起使用,以防止当前的循环迭代结果累积到结果列表中。以下示例将数组表过滤为仅包含偶数的数组: | 2332 | 继续语句也可以与各种循环表达式一起使用,以防止当前的循环迭代结果累积到结果列表中。以下示例将数组表过滤为仅包含偶数的数组: |
2333 | 2333 | ||
2334 | ```moonscript | 2334 | ```moonscript |
2335 | my_numbers = {1, 2, 3, 4, 5, 6} | 2335 | my_numbers = [1, 2, 3, 4, 5, 6] |
2336 | odds = for x in *my_numbers | 2336 | odds = for x in *my_numbers |
2337 | continue if x % 2 == 1 | 2337 | continue if x % 2 == 1 |
2338 | x | 2338 | x |
2339 | ``` | 2339 | ``` |
2340 | <YueDisplay> | 2340 | <YueDisplay> |
2341 | <pre> | 2341 | <pre> |
2342 | my_numbers = {1, 2, 3, 4, 5, 6} | 2342 | my_numbers = [1, 2, 3, 4, 5, 6] |
2343 | odds = for x in *my_numbers | 2343 | odds = for x in *my_numbers |
2344 | continue if x % 2 == 1 | 2344 | continue if x % 2 == 1 |
2345 | x | 2345 | x |
@@ -2453,7 +2453,7 @@ print "你真幸运!" unless math.random! > 0.1 | |||
2453 | ```moonscript | 2453 | ```moonscript |
2454 | a = 5 | 2454 | a = 5 |
2455 | 2455 | ||
2456 | if a in {1, 3, 5, 7} | 2456 | if a in [1, 3, 5, 7] |
2457 | print "检查离散值的相等性" | 2457 | print "检查离散值的相等性" |
2458 | 2458 | ||
2459 | if a in list | 2459 | if a in list |
@@ -2463,7 +2463,7 @@ if a in list | |||
2463 | <pre> | 2463 | <pre> |
2464 | a = 5 | 2464 | a = 5 |
2465 | 2465 | ||
2466 | if a in {1, 3, 5, 7} | 2466 | if a in [1, 3, 5, 7] |
2467 | print "检查离散值的相等性" | 2467 | print "检查离散值的相等性" |
2468 | 2468 | ||
2469 | if a in list | 2469 | if a in list |
@@ -2741,7 +2741,7 @@ inv\add_item "pants" | |||
2741 | 2741 | ||
2742 | ```moonscript | 2742 | ```moonscript |
2743 | class Person | 2743 | class Person |
2744 | clothes: {} | 2744 | clothes: [] |
2745 | give_item: (name)=> | 2745 | give_item: (name)=> |
2746 | table.insert @clothes, name | 2746 | table.insert @clothes, name |
2747 | 2747 | ||
@@ -2757,7 +2757,7 @@ print item for item in *a.clothes | |||
2757 | <YueDisplay> | 2757 | <YueDisplay> |
2758 | <pre> | 2758 | <pre> |
2759 | class Person | 2759 | class Person |
2760 | clothes: {} | 2760 | clothes: [] |
2761 | give_item: (name)=> | 2761 | give_item: (name)=> |
2762 | table.insert @clothes, name | 2762 | table.insert @clothes, name |
2763 | 2763 | ||
@@ -2777,13 +2777,13 @@ print item for item in *a.clothes | |||
2777 | ```moonscript | 2777 | ```moonscript |
2778 | class Person | 2778 | class Person |
2779 | new: => | 2779 | new: => |
2780 | @clothes = {} | 2780 | @clothes = [] |
2781 | ``` | 2781 | ``` |
2782 | <YueDisplay> | 2782 | <YueDisplay> |
2783 | <pre> | 2783 | <pre> |
2784 | class Person | 2784 | class Person |
2785 | new: => | 2785 | new: => |
2786 | @clothes = {} | 2786 | @clothes = [] |
2787 | </pre> | 2787 | </pre> |
2788 | </YueDisplay> | 2788 | </YueDisplay> |
2789 | 2789 | ||
@@ -3239,7 +3239,7 @@ create_person = (name, relatives)-> | |||
3239 | .name = name | 3239 | .name = name |
3240 | \add_relative relative for relative in *relatives | 3240 | \add_relative relative for relative in *relatives |
3241 | 3241 | ||
3242 | me = create_person "Leaf", {dad, mother, sister} | 3242 | me = create_person "Leaf", [dad, mother, sister] |
3243 | ``` | 3243 | ``` |
3244 | <YueDisplay> | 3244 | <YueDisplay> |
3245 | <pre> | 3245 | <pre> |
@@ -3248,7 +3248,7 @@ create_person = (name, relatives)-> | |||
3248 | .name = name | 3248 | .name = name |
3249 | \add_relative relative for relative in *relatives | 3249 | \add_relative relative for relative in *relatives |
3250 | 3250 | ||
3251 | me = create_person "Leaf", {dad, mother, sister} | 3251 | me = create_person "Leaf", [dad, mother, sister] |
3252 | </pre> | 3252 | </pre> |
3253 | </YueDisplay> | 3253 | </YueDisplay> |
3254 | 3254 | ||