From 2dc090daf42d9449b2c63e7167084092d0bd13ac Mon Sep 17 00:00:00 2001 From: Li Jin Date: Tue, 31 Oct 2023 16:06:05 +0800 Subject: fix doc. add busted to testing work. --- doc/docs/doc/README.md | 112 +++++++++++++++++++++++----------------------- doc/docs/zh/doc/README.md | 106 +++++++++++++++++++++---------------------- 2 files changed, 109 insertions(+), 109 deletions(-) (limited to 'doc') diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index aaeea2d..54c6b72 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -30,7 +30,7 @@ inventory = count: 3 -- pipe operator -{1, 2, 3} +[1, 2, 3] |> map (x)-> x * 2 |> filter (x)-> x > 4 |> reduce 0, (a, b)-> a + b @@ -62,7 +62,7 @@ inventory = count: 3 -- pipe operator -{1, 2, 3} +[1, 2, 3] |> map (x)-> x * 2 |> filter (x)-> x > 4 |> reduce 0, (a, b)-> a + b @@ -339,7 +339,7 @@ import "utils" as { $, -- symbol to import all macros $foreach: $each -- rename macro $foreach to $each } -{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ +[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ ```
@@ -355,7 +355,7 @@ import "utils" as {
   $, -- symbol to import all macros
   $foreach: $each -- rename macro $foreach to $each
 }
-{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
+[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
 ]]
 
@@ -467,12 +467,12 @@ The middle expression is only evaluated once, rather than twice as it would be i The **[] =** operator is used to append values to tables. ```moonscript -tab = {} +tab = [] tab[] = "Value" ```
-tab = {}
+tab = []
 tab[] = "Value"
 
@@ -1106,27 +1106,27 @@ This also works with nested data structures as well: ```moonscript obj2 = { - numbers: {1,2,3,4} + numbers: [1, 2, 3, 4] properties: { color: "green" height: 13.5 } } -{numbers: {first, second}} = obj2 +{numbers: [first, second]} = obj2 print first, second, color ```
 obj2 = {
-  numbers: {1,2,3,4}
+  numbers: [1, 2, 3, 4]
   properties: {
     color: "green"
     height: 13.5
   }
 }
 
-{numbers: {first, second}} = obj2
+{numbers: [first, second]} = obj2
 print first, second, color
 
@@ -1135,7 +1135,7 @@ If the destructuring statement is complicated, feel free to spread it out over a ```moonscript { - numbers: {first, second} + numbers: [first, second] properties: { color: color } @@ -1144,7 +1144,7 @@ If the destructuring statement is complicated, feel free to spread it out over a
 {
-  numbers: {first, second}
+  numbers: [first, second]
   properties: {
     color: color
   }
@@ -1188,11 +1188,11 @@ You can write default values while doing destructuring like:
 You can use `_` as placeholder when doing a list destructuring:
 
 ```moonscript
-{_, two, _, four} = items
+[_, two, _, four] = items
 ```
 
 
-{_, two, _, four} = items
+[_, two, _, four] = items
 
@@ -1201,22 +1201,22 @@ You can use `_` as placeholder when doing a list destructuring: Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: ```moonscript -tuples = { - {"hello", "world"} - {"egg", "head"} -} +tuples = [ + ["hello", "world"] + ["egg", "head"] +] -for {left, right} in *tuples +for [left, right] in *tuples print left, right ```
-tuples = {
-  {"hello", "world"}
-  {"egg", "head"}
-}
+tuples = [
+  ["hello", "world"]
+  ["egg", "head"]
+]
 
-for {left, right} in *tuples
+for [left, right] in *tuples
   print left, right
 
@@ -1275,7 +1275,7 @@ print "OK" You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way. ```moonscript -list = {1, 2, 3, 4, 5} +list = [1, 2, 3, 4, 5] fn = (ok) -> ok, table.unpack list ok, ... = fn true count = select '#', ... @@ -1284,7 +1284,7 @@ print ok, count, first ```
-list = {1, 2, 3, 4, 5}
+list = [1, 2, 3, 4, 5]
 fn = (ok) -> ok, table.unpack list
 ok, ... = fn true
 count = select '#', ...
@@ -1731,36 +1731,36 @@ my_func 5, 6, 7,
 Because tables also use the comma as a delimiter, this indentation syntax is helpful for letting values be part of the argument list instead of being part of the table.
 
 ```moonscript
-x = {
+x = [
   1, 2, 3, 4, a_func 4, 5,
     5, 6,
   8, 9, 10
-}
+]
 ```
 
 
-x = {
+x = [
   1, 2, 3, 4, a_func 4, 5,
     5, 6,
   8, 9, 10
-}
+]
 
Although uncommon, notice how we can give a deeper indentation for function arguments if we know we will be using a lower indentation further on. ```moonscript -y = { my_func 1, 2, 3, +y = [ my_func 1, 2, 3, 4, 5, 5, 6, 7 -} +] ```
-y = { my_func 1, 2, 3,
+y = [ my_func 1, 2, 3,
    4, 5,
   5, 6, 7
-}
+]
 
@@ -1826,12 +1826,12 @@ print @value You can specify a placeholder for where you want the backcall function to go as a parameter. ```moonscript -(x) <- map _, {1, 2, 3} +(x) <- map _, [1, 2, 3] x * 2 ```
-(x) <- map _, {1, 2, 3}
+(x) <- map _, [1, 2, 3]
 x * 2
 
@@ -1862,11 +1862,11 @@ print result, msg Like in Lua, tables are delimited in curly braces. ```moonscript -some_values = { 1, 2, 3, 4 } +some_values = [1, 2, 3, 4] ```
-some_values = { 1, 2, 3, 4 }
+some_values = [1, 2, 3, 4]
 
@@ -1895,14 +1895,14 @@ The curly braces can be left off if a single table of key value pairs is being a profile = height: "4 feet", shoe_size: 13, - favorite_foods: {"ice cream", "donuts"} + favorite_foods: ["ice cream", "donuts"] ```
 profile =
   height: "4 feet",
   shoe_size: 13,
-  favorite_foods: {"ice cream", "donuts"}
+  favorite_foods: ["ice cream", "donuts"]
 
@@ -1998,13 +1998,13 @@ t = { Lua tables have both an array part and a hash part, but sometimes you want to make a semantic distinction between array and hash usage when writing Lua tables. Then you can write Lua table with **[ ]** instead of **{ }** to represent an array table and writing any key value pair in a list table won't be allowed. ```moonscript -some_values = [ 1, 2, 3, 4 ] -list_with_one_element = [ 1, ] +some_values = [1, 2, 3, 4] +list_with_one_element = [1, ] ```
-some_values = [ 1, 2, 3, 4 ]
-list_with_one_element = [ 1, ]
+some_values = [1, 2, 3, 4]
+list_with_one_element = [1, ]
 
@@ -2137,12 +2137,12 @@ The key-value tuple in a table comprehension can also come from a single express In this example we convert an array of pairs to a table where the first item in the pair is the key and the second is the value. ```moonscript -tuples = {{"hello", "world"}, {"foo", "bar"}} +tuples = [ ["hello", "world"], ["foo", "bar"]] tbl = {unpack tuple for tuple in *tuples} ```
-tuples = { {"hello", "world"}, {"foo", "bar"} }
+tuples = [ ["hello", "world"], ["foo", "bar"]]
 tbl = {unpack tuple for tuple in *tuples}
 
@@ -2371,14 +2371,14 @@ while i < 10 continue can also be used with loop expressions to prevent that iteration from accumulating into the result. This examples filters the array table into just even numbers: ```moonscript -my_numbers = {1, 2, 3, 4, 5, 6} +my_numbers = [1, 2, 3, 4, 5, 6] odds = for x in *my_numbers continue if x % 2 == 1 x ```
-my_numbers = {1, 2, 3, 4, 5, 6}
+my_numbers = [1, 2, 3, 4, 5, 6]
 odds = for x in *my_numbers
   continue if x % 2 == 1
   x
@@ -2492,7 +2492,7 @@ You can write range checking code with an `in-expression`.
 ```moonscript
 a = 5
 
-if a in {1, 3, 5, 7}
+if a in [1, 3, 5, 7]
   print "checking equality with discrete values"
 
 if a in list
@@ -2502,7 +2502,7 @@ if a in list
 
 a = 5
 
-if a in {1, 3, 5, 7}
+if a in [1, 3, 5, 7]
   print "checking equality with discrete values"
 
 if a in list
@@ -2780,7 +2780,7 @@ Consider the example below, the clothes property is shared amongst all instances
 
 ```moonscript
 class Person
-  clothes: {}
+  clothes: []
   give_item: (name)=>
     table.insert @clothes, name
 
@@ -2796,7 +2796,7 @@ print item for item in *a.clothes
 
 
 class Person
-  clothes: {}
+  clothes: []
   give_item: (name)=>
     table.insert @clothes, name
 
@@ -2816,13 +2816,13 @@ The proper way to avoid this problem is to create the mutable state of the objec
 ```moonscript
 class Person
   new: =>
-    @clothes = {}
+    @clothes = []
 ```
 
 
 class Person
   new: =>
-    @clothes = {}
+    @clothes = []
 
@@ -3278,7 +3278,7 @@ create_person = (name, relatives)-> .name = name \add_relative relative for relative in *relatives -me = create_person "Leaf", {dad, mother, sister} +me = create_person "Leaf", [dad, mother, sister] ```
@@ -3287,7 +3287,7 @@ create_person = (name,  relatives)->
     .name = name
     \add_relative relative for relative in *relatives
 
-me = create_person "Leaf", {dad, mother, sister}
+me = create_person "Leaf", [dad, mother, sister]
 
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 = count: 3 -- 管道操作符 -{1, 2, 3} +[1, 2, 3] |> map (x)-> x * 2 |> filter (x)-> x > 4 |> reduce 0, (a, b)-> a + b @@ -62,7 +62,7 @@ inventory = count: 3 -- 管道操作符 -{1, 2, 3} +[1, 2, 3] |> map (x)-> x * 2 |> filter (x)-> x > 4 |> reduce 0, (a, b)-> a + b @@ -336,7 +336,7 @@ import "utils" as { $, -- 表示导入所有宏的符号 $foreach: $each -- 重命名宏 $foreach 为 $each } -{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ +[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ ```
@@ -352,7 +352,7 @@ import "utils" as {
   $, -- 表示导入所有宏的符号
   $foreach: $each -- 重命名宏 $foreach 为 $each
 }
-{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
+[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
 ]]
 
@@ -465,12 +465,12 @@ print v(1) > v(2) <= v(3) **[] =** 操作符用于向Lua表的最后插入值。 ```moonscript -tab = {} +tab = [] tab[] = "Value" ```
-tab = {}
+tab = []
 tab[] = "Value"
 
@@ -1104,27 +1104,27 @@ print hello, the_day ```moonscript obj2 = { - numbers: {1,2,3,4} + numbers: [1,2,3,4] properties: { color: "green" height: 13.5 } } -{numbers: {first, second}} = obj2 +{numbers: [first, second]} = obj2 print first, second, color ```
 obj2 = {
-  numbers: {1,2,3,4}
+  numbers: [1,2,3,4]
   properties: {
     color: "green"
     height: 13.5
   }
 }
 
-{numbers: {first, second}} = obj2
+{numbers: [first, second]} = obj2
 print first, second, color
 
@@ -1133,7 +1133,7 @@ print first, second, color ```moonscript { - numbers: {first, second} + numbers: [first, second] properties: { color: color } @@ -1142,7 +1142,7 @@ print first, second, color
 {
-  numbers: {first, second}
+  numbers: [first, second]
   properties: {
     color: color
   }
@@ -1186,7 +1186,7 @@ print first, second, color
 在进行列表解构时,您可以使用`_`作为占位符:
 
 ```moonscript
-{_, two, _, four} = items
+[_, two, _, four] = items
 ```
 
 
@@ -1199,22 +1199,22 @@ print first, second, color
 解构也可以出现在其它隐式进行赋值的地方。一个例子是用在for循环:
 
 ```moonscript
-tuples = {
-  {"hello", "world"}
-  {"egg", "head"}
-}
+tuples = [
+  ["hello", "world"]
+  ["egg", "head"]
+]
 
-for {left, right} in *tuples
+for [left, right] in *tuples
   print left, right
 ```
 
 
-tuples = {
-  {"hello", "world"}
-  {"egg", "head"}
-}
+tuples = [
+  ["hello", "world"]
+  ["egg", "head"]
+]
 
-for {left, right} in *tuples
+for [left, right] in *tuples
   print left, right
 
@@ -1273,7 +1273,7 @@ print "好的" 您可以将函数返回的结果赋值给一个可变参数符号 `...`。然后使用Lua的方式访问其内容。 ```moonscript -list = {1, 2, 3, 4, 5} +list = [1, 2, 3, 4, 5] fn = (ok) -> ok, table.unpack list ok, ... = fn true count = select '#', ... @@ -1282,7 +1282,7 @@ print ok, count, first ```
-list = {1, 2, 3, 4, 5}
+list = [1, 2, 3, 4, 5]
 fn = (ok) -> ok, table.unpack list
 ok, ... = fn true
 count = select '#', ...
@@ -1691,36 +1691,36 @@ my_func 5, 6, 7,
 因为Lua表也使用逗号作为分隔符,这种缩进语法有助于让值成为参数列表的一部分,而不是Lua表的一部分。
 
 ```moonscript
-x = {
+x = [
   1, 2, 3, 4, a_func 4, 5,
     5, 6,
   8, 9, 10
-}
+]
 ```
 
 
-x = {
+x = [
   1, 2, 3, 4, a_func 4, 5,
     5, 6,
   8, 9, 10
-}
+]
 
有个不常见的写法可以注意一下,如果我们将在后面使用较低的缩进,我们可以为函数参数提供更深的缩进来区分列表的归属。 ```moonscript -y = { my_func 1, 2, 3, +y = [ my_func 1, 2, 3, 4, 5, 5, 6, 7 -} +] ```
-y = { my_func 1, 2, 3,
+y = [ my_func 1, 2, 3,
    4, 5,
   5, 6, 7
-}
+]
 
@@ -1786,12 +1786,12 @@ print @value 您可以通过一个占位符指定回调函数的传参位置。 ```moonscript -(x) <- map _, {1, 2, 3} +(x) <- map _, [1, 2, 3] x * 2 ```
-(x) <- map _, {1, 2, 3}
+(x) <- map _, [1, 2, 3]
 x * 2
 
@@ -1822,11 +1822,11 @@ print result, msg 和Lua一样,表格可以通过花括号进行定义。 ```moonscript -some_values = { 1, 2, 3, 4 } +some_values = [1, 2, 3, 4] ```
-some_values = { 1, 2, 3, 4 }
+some_values = [1, 2, 3, 4]
 
@@ -1855,14 +1855,14 @@ some_values = { profile = height: "4英尺", shoe_size: 13, - favorite_foods: {"冰淇淋", "甜甜圈"} + favorite_foods: ["冰淇淋", "甜甜圈"] ```
 profile =
   height: "4英尺",
   shoe_size: 13,
-  favorite_foods: {"冰淇淋", "甜甜圈"}
+  favorite_foods: ["冰淇淋", "甜甜圈"]
 
@@ -1977,12 +1977,12 @@ list_with_one_element = [ 1, ] 以下操作创建了一个items表的副本,但所有包含的值都翻倍了。 ```moonscript -items = [ 1, 2, 3, 4 ] +items = [1, 2, 3, 4] doubled = [item * 2 for i, item in ipairs items] ```
-items = [ 1, 2, 3, 4 ]
+items = [1, 2, 3, 4]
 doubled = [item * 2 for i, item in ipairs items]
 
@@ -2097,12 +2097,12 @@ sqrts = {i, math.sqrt i for i in *numbers} 在下面的示例中,我们将一些数组转换为一个表,其中每个数组里的第一项是键,第二项是值。 ```moonscript -tuples = {{"hello", "world"}, {"foo", "bar"}} +tuples = [ ["hello", "world"], ["foo", "bar"]] tbl = {unpack tuple for tuple in *tuples} ```
-tuples = { {"hello", "world"}, {"foo", "bar"} }
+tuples = [ ["hello", "world"], ["foo", "bar"]]
 tbl = {unpack tuple for tuple in *tuples}
 
@@ -2332,14 +2332,14 @@ while i < 10 继续语句也可以与各种循环表达式一起使用,以防止当前的循环迭代结果累积到结果列表中。以下示例将数组表过滤为仅包含偶数的数组: ```moonscript -my_numbers = {1, 2, 3, 4, 5, 6} +my_numbers = [1, 2, 3, 4, 5, 6] odds = for x in *my_numbers continue if x % 2 == 1 x ```
-my_numbers = {1, 2, 3, 4, 5, 6}
+my_numbers = [1, 2, 3, 4, 5, 6]
 odds = for x in *my_numbers
   continue if x % 2 == 1
   x
@@ -2453,7 +2453,7 @@ print "你真幸运!" unless math.random! > 0.1
 ```moonscript
 a = 5
 
-if a in {1, 3, 5, 7}
+if a in [1, 3, 5, 7]
   print "检查离散值的相等性"
 
 if a in list
@@ -2463,7 +2463,7 @@ if a in list
 
 a = 5
 
-if a in {1, 3, 5, 7}
+if a in [1, 3, 5, 7]
   print "检查离散值的相等性"
 
 if a in list
@@ -2741,7 +2741,7 @@ inv\add_item "pants"
 
 ```moonscript
 class Person
-  clothes: {}
+  clothes: []
   give_item: (name)=>
     table.insert @clothes, name
 
@@ -2757,7 +2757,7 @@ print item for item in *a.clothes
 
 
 class Person
-  clothes: {}
+  clothes: []
   give_item: (name)=>
     table.insert @clothes, name
 
@@ -2777,13 +2777,13 @@ print item for item in *a.clothes
 ```moonscript
 class Person
   new: =>
-    @clothes = {}
+    @clothes = []
 ```
 
 
 class Person
   new: =>
-    @clothes = {}
+    @clothes = []
 
@@ -3239,7 +3239,7 @@ create_person = (name, relatives)-> .name = name \add_relative relative for relative in *relatives -me = create_person "Leaf", {dad, mother, sister} +me = create_person "Leaf", [dad, mother, sister] ```
@@ -3248,7 +3248,7 @@ create_person = (name,  relatives)->
     .name = name
     \add_relative relative for relative in *relatives
 
-me = create_person "Leaf", {dad, mother, sister}
+me = create_person "Leaf", [dad, mother, sister]
 
-- cgit v1.2.3-55-g6feb