From 1bfcc36f001cd129a4213ca19f26f3d688eb94ff Mon Sep 17 00:00:00 2001 From: Li Jin Date: Wed, 8 Jan 2025 09:28:00 +0800 Subject: Updated docs. --- doc/docs/doc/README.md | 164 ++++++++++++++++++++++++---------------------- doc/docs/zh/doc/README.md | 164 ++++++++++++++++++++++++---------------------- 2 files changed, 170 insertions(+), 158 deletions(-) (limited to 'doc') diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 814593b..e268dc8 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -31,16 +31,19 @@ inventory = -- pipe operator [1, 2, 3] - |> map (x)-> x * 2 - |> filter (x)-> x > 4 - |> reduce 0, (a, b)-> a + b + |> map (x) -> x * 2 + |> filter (x) -> x > 4 + |> reduce 0, (a, b) -> a + b |> print -- metatable manipulation apple = size: 15 - : {color: 0x00ffff} -p apple.color, apple. if apple.<>? + : + color: 0x00ffff + +with apple + p .size, .color, . if .<>? -- js-like export syntax export 🌛 = "月之脚本" @@ -63,16 +66,19 @@ inventory = -- pipe operator [1, 2, 3] - |> map (x)-> x * 2 - |> filter (x)-> x > 4 - |> reduce 0, (a, b)-> a + b + |> map (x) -> x * 2 + |> filter (x) -> x > 4 + |> reduce 0, (a, b) -> a + b |> print -- metatable manipulation apple = size: 15 - <index>: {color: 0x00ffff} -p apple.color, apple.<index> if apple.<>? + <index>: + color: 0x00ffff + +with apple + p .size, .color, .<index> if .<>? -- js-like export syntax export 🌛 = "月之脚本" @@ -210,14 +216,14 @@ area = $PI2 * 5 macro HELLO = -> "'hello world'" print $HELLO -macro config = (debugging)-> +macro config = (debugging) -> global debugMode = debugging == "true" "" -macro asserts = (cond)-> +macro asserts = (cond) -> debugMode and "assert #{cond}" or "" -macro assert = (cond)-> +macro assert = (cond) -> debugMode and "assert #{cond}" or "#{cond}" $config true @@ -227,7 +233,7 @@ $config false value = $assert item -- the passed expressions are treated as strings -macro and = (...)-> "#{ table.concat {...}, ' and ' }" +macro and = (...) -> "#{ table.concat {...}, ' and ' }" if $and f1!, f2!, f3! print "OK" ``` @@ -239,14 +245,14 @@ area = $PI2 * 5 macro HELLO = -> "'hello world'" print $HELLO -macro config = (debugging)-> +macro config = (debugging) -> global debugMode = debugging == "true" "" -macro asserts = (cond)-> +macro asserts = (cond) -> debugMode and "assert #{cond}" or "" -macro assert = (cond)-> +macro assert = (cond) -> debugMode and "assert #{cond}" or "#{cond}" $config true @@ -256,7 +262,7 @@ $config false value = $assert item -- the passed expressions are treated as strings -macro and = (...)-> "#{ table.concat {...}, ' and ' }" +macro and = (...) -> "#{ table.concat {...}, ' and ' }" if $and f1!, f2!, f3! print "OK" @@ -266,21 +272,21 @@ if $and f1!, f2!, f3! A macro function can either return a YueScript string or a config table containing Lua codes. ```moonscript -macro yueFunc = (var)-> "local #{var} = ->" +macro yueFunc = (var) -> "local #{var} = ->" $yueFunc funcA -funcA = -> "assign the Yue defined variable" +funcA = -> "fail to assign to the Yue defined variable" -- take care and let YueScript know the -- local variables you declared in Lua code -macro luaFunc = (var)-> { +macro luaFunc = (var) -> { code: "local function #{var}() end" type: "lua" locals: {var} } $luaFunc funcB -funcB = -> "assign the Lua defined variable" +funcB = -> "assign to the Lua defined variable" -macro lua = (code)-> { +macro lua = (code) -> { :code type: "lua" } @@ -295,21 +301,21 @@ end ```
-macro yueFunc = (var)-> "local #{var} = ->"
+macro yueFunc = (var) -> "local #{var} = ->"
 $yueFunc funcA
-funcA = -> "assign the Yue defined variable"
+funcA = -> "fail to assign to the Yue defined variable"
 
 -- take care and let YueScript know the
 -- local variables you declared in Lua codes
-macro luaFunc = (var)-> {
+macro luaFunc = (var) -> {
   code: "local function #{var}() end"
   type: "lua"
   locals: {var}
 }
 $luaFunc funcB
-funcB = -> "assign the Lua defined variable"
+funcB = -> "assign to the Lua defined variable"
 
-macro lua = (code)-> {
+macro lua = (code) -> {
   :code
   type: "lua"
 }
@@ -329,9 +335,9 @@ end
 Macro functions can be exported from a module and get imported in another module. You have to put export macro functions in a single file to be used, and only macro definition, macro importing and macro expansion in place can be put into the macro exporting module.
 ```moonscript
 -- file: utils.yue
-export macro map = (items, action)-> "[#{action} for _ in *#{items}]"
-export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]"
-export macro foreach = (items, action)-> "for _ in *#{items}
+export macro map = (items, action) -> "[#{action} for _ in *#{items}]"
+export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]"
+export macro foreach = (items, action) -> "for _ in *#{items}
   #{action}"
 
 -- file main.yue
@@ -344,9 +350,9 @@ import "utils" as {
 
 
 -- file: utils.yue
-export macro map = (items, action)-> "[#{action} for _ in *#{items}]"
-export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]"
-export macro foreach = (items, action)-> "for _ in *#{items}
+export macro map = (items, action) -> "[#{action} for _ in *#{items}]"
+export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]"
+export macro foreach = (items, action) -> "for _ in *#{items}
   #{action}"
 -- file main.yue
 -- import function is not available in browser, try it in a real environment
@@ -457,7 +463,7 @@ print 1 <= a <= 10
 Note the evaluation behavior of chained comparisons:
 
 ```moonscript
-v = (x)->
+v = (x) ->
 	print x
 	x
 
@@ -480,7 +486,7 @@ print v(1) > v(2) <= v(3)
 ```
 
 
-v = (x)->
+v = (x) ->
 	print x
 	x
 
@@ -567,7 +573,7 @@ Create normal table with empty bracekets **<>** or metamethod key which is surro
 
 ```moonscript
 mt = {}
-add = (right)=> <>: mt, value: @value + right.value
+add = (right) => <>: mt, value: @value + right.value
 mt.__add = add
 
 a = <>: mt, value: 1
@@ -583,7 +589,7 @@ close _ = : -> print "out of scope"
 
 
 mt = {}
-add = (right)=> <>: mt, value: @value + right.value
+add = (right) => <>: mt, value: @value + right.value
 mt.__add = add
 
 a = <>: mt, value: 1
@@ -645,7 +651,7 @@ func?!
 print abc?["hello world"]?.xyz
 
 x = tab?.value
-len = utf8?.len or string?.len or (o)-> #o
+len = utf8?.len or string?.len or (o) -> #o
 
 if print and x?
   print x
@@ -660,7 +666,7 @@ func?!
 print abc?["hello world"]?.xyz
 
 x = tab?.value
-len = utf8?.len or string?.len or (o)-> #o
+len = utf8?.len or string?.len or (o) -> #o
 
 if print and x?
   print x
@@ -1361,18 +1367,18 @@ You can write multi-line chaining function calls with a same indent.
 ```moonscript
 Rx.Observable
   .fromRange 1, 8
-  \filter (x)-> x % 2 == 0
+  \filter (x) -> x % 2 == 0
   \concat Rx.Observable.of 'who do we appreciate'
-  \map (value)-> value .. '!'
+  \map (value) -> value .. '!'
   \subscribe print
 ```
 
 
 Rx.Observable
   .fromRange 1, 8
-  \filter (x)-> x % 2 == 0
+  \filter (x) -> x % 2 == 0
   \concat Rx.Observable.of 'who do we appreciate'
-  \map (value)-> value .. '!'
+  \map (value) -> value .. '!'
   \subscribe print
 
@@ -1586,11 +1592,11 @@ func_b() Functions with arguments can be created by preceding the arrow with a list of argument names in parentheses: ```moonscript -sum = (x, y)-> print "sum", x + y +sum = (x, y) -> print "sum", x + y ```
-sum = (x, y)-> print "sum", x + y
+sum = (x, y) -> print "sum", x + y
 
@@ -1627,7 +1633,7 @@ There must not be any space between the opening parenthesis and the function. Functions will coerce the last statement in their body into a return statement, this is called implicit return: ```moonscript -sum = (x, y)-> x + y +sum = (x, y) -> x + y print "The sum is ", sum 10, 20 ``` @@ -1640,23 +1646,23 @@ print "The sum is ", sum 10, 20 And if you need to explicitly return, you can use the return keyword: ```moonscript -sum = (x, y)-> return x + y +sum = (x, y) -> return x + y ```
-sum = (x, y)-> return x + y
+sum = (x, y) -> return x + y
 
Just like in Lua, functions can return multiple values. The last statement must be a list of values separated by commas: ```moonscript -mystery = (x, y)-> x + y, x - y +mystery = (x, y) -> x + y, x - y a, b = mystery 10, 20 ```
-mystery = (x, y)-> x + y, x - y
+mystery = (x, y) -> x + y, x - y
 a, b = mystery 10, 20
 
@@ -1666,11 +1672,11 @@ a, b = mystery 10, 20 Because it is an idiom in Lua to send an object as the first argument when calling a method, a special syntax is provided for creating functions which automatically includes a self argument. ```moonscript -func = (num)=> @value + num +func = (num) => @value + num ```
-func = (num)=> @value + num
+func = (num) => @value + num
 
@@ -1679,13 +1685,13 @@ func = (num)=> @value + num It is possible to provide default values for the arguments of a function. An argument is determined to be empty if its value is nil. Any nil arguments that have a default value will be replace before the body of the function is run. ```moonscript -my_function = (name = "something", height = 100)-> +my_function = (name = "something", height = 100) -> print "Hello I am", name print "My height is", height ```
-my_function = (name = "something", height = 100)->
+my_function = (name = "something", height = 100) ->
   print "Hello I am", name
   print "My height is", height
 
@@ -1694,12 +1700,12 @@ my_function = (name = "something", height = 100)-> An argument default value expression is evaluated in the body of the function in the order of the argument declarations. For this reason default values have access to previously declared arguments. ```moonscript -some_args = (x = 100, y = x + 1000)-> +some_args = (x = 100, y = x + 1000) -> print x + y ```
-some_args = (x = 100, y = x + 1000)->
+some_args = (x = 100, y = x + 1000) ->
   print x + y
 
@@ -2787,7 +2793,7 @@ class Inventory new: => @items = {} - add_item: (name)=> + add_item: (name) => if @items[name] @items[name] += 1 else @@ -2799,7 +2805,7 @@ class Inventory new: => @items = {} - add_item: (name)=> + add_item: (name) => if @items[name] @items[name] += 1 else @@ -2839,7 +2845,7 @@ Consider the example below, the clothes property is shared amongst all instances ```moonscript class Person clothes: [] - give_item: (name)=> + give_item: (name) => table.insert @clothes, name a = Person! @@ -2855,7 +2861,7 @@ print item for item in *a.clothes
 class Person
   clothes: []
-  give_item: (name)=>
+  give_item: (name) =>
     table.insert @clothes, name
 
 a = Person!
@@ -2891,7 +2897,7 @@ The extends keyword can be used in a class declaration to inherit the properties
 ```moonscript
 class BackPack extends Inventory
   size: 10
-  add_item: (name)=>
+  add_item: (name) =>
     if #@items > size then error "backpack is full"
     super name
 ```
@@ -2899,7 +2905,7 @@ class BackPack extends Inventory
 
 class BackPack extends Inventory
   size: 10
-  add_item: (name)=>
+  add_item: (name) =>
     if #@items > size then error "backpack is full"
     super name
 
@@ -2913,7 +2919,7 @@ Whenever a class inherits from another, it sends a message to the parent class b ```moonscript class Shelf - @__inherited: (child)=> + @__inherited: (child) => print @__name, "was inherited by", child.__name -- will print: Shelf was inherited by Cupboard @@ -2922,7 +2928,7 @@ class Cupboard extends Shelf
 class Shelf
-  @__inherited: (child)=>
+  @__inherited: (child) =>
     print @__name, "was inherited by", child.__name
 
 -- will print: Shelf was inherited by Cupboard
@@ -3108,7 +3114,7 @@ All variables declared in the body of the class are local to the classes propert
 ```moonscript
 class MoreThings
   secret = 123
-  log = (msg)-> print "LOG:", msg
+  log = (msg) -> print "LOG:", msg
 
   some_method: =>
     log "hello world: " .. secret
@@ -3117,7 +3123,7 @@ class MoreThings
 
 class MoreThings
   secret = 123
-  log = (msg)-> print "LOG:", msg
+  log = (msg) -> print "LOG:", msg
 
   some_method: =>
     log "hello world: " .. secret
@@ -3144,11 +3150,11 @@ assert @@ == self.__class
 For example, a quick way to create a new instance of the same class from an instance method using @@:
 
 ```moonscript
-some_instance_method = (...)=> @@ ...
+some_instance_method = (...) => @@ ...
 ```
 
 
-some_instance_method = (...)=> @@ ...
+some_instance_method = (...) => @@ ...
 
@@ -3188,13 +3194,13 @@ class Something You can also use this syntax for a common function to initialize a object's fields. ```moonscript -new = (@fieldA, @fieldB)=> @ +new = (@fieldA, @fieldB) => @ obj = new {}, 123, "abc" print obj ```
-new = (@fieldA, @fieldB)=> @
+new = (@fieldA, @fieldB) => @
 obj = new {}, 123, "abc"
 print obj
 
@@ -3331,7 +3337,7 @@ file = with File "favorite_foods.txt" Or… ```moonscript -create_person = (name, relatives)-> +create_person = (name, relatives) -> with Person! .name = name \add_relative relative for relative in *relatives @@ -3340,7 +3346,7 @@ me = create_person "Leaf", [dad, mother, sister] ```
-create_person = (name,  relatives)->
+create_person = (name,  relatives) ->
   with Person!
     .name = name
     \add_relative relative for relative in *relatives
@@ -3465,7 +3471,7 @@ my_object = {
   write: => print "the value:", @value
 }
 
-run_callback = (func)->
+run_callback = (func) ->
   print "running callback..."
   func!
 
@@ -3484,7 +3490,7 @@ my_object = {
   write: => print "the value:", @value
 }
 
-run_callback = (func)->
+run_callback = (func) ->
   print "running callback..."
   func!
 
@@ -3544,7 +3550,7 @@ The using keyword lets us do that. using nil makes sure that no closed variables
 ```moonscript
 i = 100
 
-my_func = (using nil)->
+my_func = (using nil) ->
   i = "hello" -- a new local variable is created here
 
 my_func!
@@ -3554,7 +3560,7 @@ print i -- prints 100, i is unaffected
 
 i = 100
 
-my_func = (using nil)->
+my_func = (using nil) ->
   i = "hello" -- a new local variable is created here
 
 my_func!
@@ -3568,7 +3574,7 @@ Multiple names can be separated by commas. Closure values can still be accessed,
 tmp = 1213
 i, k = 100, 50
 
-my_func = (add using k, i)->
+my_func = (add using k, i) ->
   tmp = tmp + add -- a new local tmp is created
   i += tmp
   k += tmp
@@ -3581,7 +3587,7 @@ print i, k -- these have been updated
 tmp = 1213
 i, k = 100, 50
 
-my_func = (add using k, i)->
+my_func = (add using k, i) ->
   tmp = tmp + add -- a new local tmp is created
   i += tmp
   k += tmp
diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md
index 355e468..f34fe58 100755
--- a/doc/docs/zh/doc/README.md
+++ b/doc/docs/zh/doc/README.md
@@ -31,16 +31,19 @@ inventory =
 
 -- 管道操作符
 [1, 2, 3]
-  |> map (x)-> x * 2
-  |> filter (x)-> x > 4
-  |> reduce 0, (a, b)-> a + b
+  |> map (x) -> x * 2
+  |> filter (x) -> x > 4
+  |> reduce 0, (a, b) -> a + b
   |> print
 
 -- 元表操作
 apple =
   size: 15
-  : {color: 0x00ffff}
-p apple.color, apple. if apple.<>?
+  :
+    color: 0x00ffff
+
+with apple
+  p .size, .color, . if .<>?
 
 -- 类似js的导出语法
 export 🌛 = "月之脚本"
@@ -63,16 +66,19 @@ inventory =
 
 -- 管道操作符
 [1, 2, 3]
-  |> map (x)-> x * 2
-  |> filter (x)-> x > 4
-  |> reduce 0, (a, b)-> a + b
+  |> map (x) -> x * 2
+  |> filter (x) -> x > 4
+  |> reduce 0, (a, b) -> a + b
   |> print
 
 -- 元表操作
 apple =
   size: 15
-  <index>: {color: 0x00ffff}
-p apple.color, apple.<index> if apple.<>?
+  <index>:
+    color: 0x00ffff
+
+with apple
+  p .size, .color, .<index> if .<>?
 
 -- 类似js的导出语法
 export 🌛 = "月之脚本"
@@ -209,14 +215,14 @@ area = $PI2 * 5
 macro HELLO = -> "'你好 世界'"
 print $HELLO
 
-macro config = (debugging)->
+macro config = (debugging) ->
   global debugMode = debugging == "true"
   ""
 
-macro asserts = (cond)->
+macro asserts = (cond) ->
   debugMode and "assert #{cond}" or ""
 
-macro assert = (cond)->
+macro assert = (cond) ->
   debugMode and "assert #{cond}" or "#{cond}"
 
 $config true
@@ -226,7 +232,7 @@ $config false
 value = $assert item
 
 -- 宏函数参数传递的表达式会被转换为字符串
-macro and = (...)-> "#{ table.concat {...}, ' and ' }"
+macro and = (...) -> "#{ table.concat {...}, ' and ' }"
 if $and f1!, f2!, f3!
   print "OK"
 ```
@@ -238,14 +244,14 @@ area = $PI2 * 5
 macro HELLO = -> "'你好 世界'"
 print $HELLO
 
-macro config = (debugging)->
+macro config = (debugging) ->
   global debugMode = debugging == "true"
   ""
 
-macro asserts = (cond)->
+macro asserts = (cond) ->
   debugMode and "assert #{cond}" or ""
 
-macro assert = (cond)->
+macro assert = (cond) ->
   debugMode and "assert #{cond}" or "#{cond}"
 
 $config true
@@ -255,7 +261,7 @@ $config false
 value = $assert item
 
 -- 宏函数参数传递的表达式会被转换为字符串
-macro and = (...)-> "#{ table.concat {...}, ' and ' }"
+macro and = (...) -> "#{ table.concat {...}, ' and ' }"
 if $and f1!, f2!, f3!
   print "OK"
 
@@ -265,20 +271,20 @@ if $and f1!, f2!, f3! 宏函数可以返回一个包含月之脚本代码的字符串,或是一个包含Lua代码字符串的配置表。 ```moonscript -macro yueFunc = (var)-> "local #{var} = ->" +macro yueFunc = (var) -> "local #{var} = ->" $yueFunc funcA -funcA = -> "访问月之脚本定义的变量" +funcA = -> "无法访问宏生成月之脚本里定义的变量" -- 让月之脚本知道你在Lua代码中声明的局部变量 -macro luaFunc = (var)-> { +macro luaFunc = (var) -> { code: "local function #{var}() end" type: "lua" locals: {var} } $luaFunc funcB -funcB = -> "访问Lua代码里定义的变量" +funcB = -> "访问宏生成Lua代码里定义的变量" -macro lua = (code)-> { +macro lua = (code) -> { :code type: "lua" } @@ -293,20 +299,20 @@ end ```
-macro yueFunc = (var)-> "local #{var} = ->"
+macro yueFunc = (var) -> "local #{var} = ->"
 $yueFunc funcA
-funcA = -> "访问月之脚本定义的变量"
+funcA = -> "无法访问宏生成月之脚本里定义的变量"
 
 -- 让月之脚本知道你在Lua代码中声明的局部变量
-macro luaFunc = (var)-> {
+macro luaFunc = (var) -> {
   code: "local function #{var}() end"
   type: "lua"
   locals: {var}
 }
 $luaFunc funcB
-funcB = -> "访问Lua代码里定义的变量"
+funcB = -> "访问宏生成Lua代码里定义的变量"
 
-macro lua = (code)-> {
+macro lua = (code) -> {
   :code
   type: "lua"
 }
@@ -326,9 +332,9 @@ end
 宏函数可以从一个模块中导出,并在另一个模块中导入。您必须将导出的宏函数放在一个单独的文件中使用,而且只有宏定义、宏导入和宏展开可以放入这个宏导出模块中。
 ```moonscript
 -- 文件: utils.yue
-export macro map = (items, action)-> "[#{action} for _ in *#{items}]"
-export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]"
-export macro foreach = (items, action)-> "for _ in *#{items}
+export macro map = (items, action) -> "[#{action} for _ in *#{items}]"
+export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]"
+export macro foreach = (items, action) -> "for _ in *#{items}
   #{action}"
 
 -- 文件 main.yue
@@ -341,9 +347,9 @@ import "utils" as {
 
 
 -- 文件: utils.yue
-export macro map = (items, action)-> "[#{action} for _ in *#{items}]"
-export macro filter = (items, action)-> "[_ for _ in *#{items} when #{action}]"
-export macro foreach = (items, action)-> "for _ in *#{items}
+export macro map = (items, action) -> "[#{action} for _ in *#{items}]"
+export macro filter = (items, action) -> "[_ for _ in *#{items} when #{action}]"
+export macro foreach = (items, action) -> "for _ in *#{items}
   #{action}"
 -- 文件 main.yue
 -- 在浏览器中不支持import函数,请在真实环境中尝试
@@ -453,7 +459,7 @@ print 1 <= a <= 10
 可以注意一下链式比较表达式的求值行为:
 
 ```moonscript
-v = (x)->
+v = (x) ->
 	print x
 	x
 
@@ -476,7 +482,7 @@ print v(1) > v(2) <= v(3)
 ```
 
 
-v = (x)->
+v = (x) ->
 	print x
 	x
 
@@ -564,7 +570,7 @@ merge = {...a, ...b}
 
 ```moonscript
 mt = {}
-add = (right)=> <>: mt, value: @value + right.value
+add = (right) => <>: mt, value: @value + right.value
 mt.__add = add
 
 a = <>: mt, value: 1
@@ -580,7 +586,7 @@ close _ = : -> print "超出范围"
 
 
 mt = {}
-add = (right)=> <>: mt, value: @value + right.value
+add = (right) => <>: mt, value: @value + right.value
 mt.__add = add
 
 a = <>: mt, value: 1
@@ -642,7 +648,7 @@ func?!
 print abc?["你好 世界"]?.xyz
 
 x = tab?.value
-len = utf8?.len or string?.len or (o)-> #o
+len = utf8?.len or string?.len or (o) -> #o
 
 if print and x?
   print x
@@ -657,7 +663,7 @@ func?!
 print abc?["你好 世界"]?.xyz
 
 x = tab?.value
-len = utf8?.len or string?.len or (o)-> #o
+len = utf8?.len or string?.len or (o) -> #o
 
 if print and x?
   print x
@@ -1358,18 +1364,18 @@ print ok, count, first
 ```moonscript
 Rx.Observable
   .fromRange 1, 8
-  \filter (x)-> x % 2 == 0
+  \filter (x) -> x % 2 == 0
   \concat Rx.Observable.of 'who do we appreciate'
-  \map (value)-> value .. '!'
+  \map (value) -> value .. '!'
   \subscribe print
 ```
 
 
 Rx.Observable
   .fromRange 1, 8
-  \filter (x)-> x % 2 == 0
+  \filter (x) -> x % 2 == 0
   \concat Rx.Observable.of 'who do we appreciate'
-  \map (value)-> value .. '!'
+  \map (value) -> value .. '!'
   \subscribe print
 
@@ -1583,11 +1589,11 @@ func_b() 带有参数的函数可以通过在箭头前加上括号中的参数名列表来进行创建: ```moonscript -sum = (x, y)-> print "数字的和", x + y +sum = (x, y) -> print "数字的和", x + y ```
-sum = (x, y)-> print "数字的和", x + y
+sum = (x, y) -> print "数字的和", x + y
 
@@ -1624,7 +1630,7 @@ print "x:", sum(10, 20), "y:", sum(30, 40) 函数会将函数体中的最后一个语句强制转换为返回语句,这被称作隐式返回: ```moonscript -sum = (x, y)-> x + y +sum = (x, y) -> x + y print "数字的和是", sum 10, 20 ``` @@ -1637,23 +1643,23 @@ print "数字的和是", sum 10, 20 如果您需要做显式返回,可以使用return关键字: ```moonscript -sum = (x, y)-> return x + y +sum = (x, y) -> return x + y ```
-sum = (x, y)-> return x + y
+sum = (x, y) -> return x + y
 
就像在Lua中一样,函数可以返回多个值。最后一个语句必须是由逗号分隔的值列表: ```moonscript -mystery = (x, y)-> x + y, x - y +mystery = (x, y) -> x + y, x - y a, b = mystery 10, 20 ```
-mystery = (x, y)-> x + y, x - y
+mystery = (x, y) -> x + y, x - y
 a, b = mystery 10, 20
 
@@ -1663,11 +1669,11 @@ a, b = mystery 10, 20 因为在Lua中调用方法时,经常习惯将对象作为第一个参数传入,所以月之脚本提供了一种特殊的语法来创建自动包含self参数的函数。 ```moonscript -func = (num)=> @value + num +func = (num) => @value + num ```
-func = (num)=> @value + num
+func = (num) => @value + num
 
@@ -1676,13 +1682,13 @@ func = (num)=> @value + num 可以为函数的参数提供默认值。如果参数的值为nil,则确定该参数为空。任何具有默认值的nil参数在函数体运行之前都会被替换。 ```moonscript -my_function = (name = "某物", height = 100)-> +my_function = (name = "某物", height = 100) -> print "你好,我是", name print "我的高度是", height ```
-my_function = (name = "某物", height = 100)->
+my_function = (name = "某物", height = 100) ->
   print "你好,我是", name
   print "我的高度是", height
 
@@ -1691,12 +1697,12 @@ my_function = (name = "某物", height = 100)-> 函数参数的默认值表达式在函数体中会按参数声明的顺序进行计算。因此,在默认值的表达式中可以访问先前声明的参数。 ```moonscript -some_args = (x = 100, y = x + 1000)-> +some_args = (x = 100, y = x + 1000) -> print x + y ```
-some_args = (x = 100, y = x + 1000)->
+some_args = (x = 100, y = x + 1000) ->
   print x + y
 
@@ -2747,7 +2753,7 @@ class Inventory new: => @items = {} - add_item: (name)=> + add_item: (name) => if @items[name] @items[name] += 1 else @@ -2759,7 +2765,7 @@ class Inventory new: => @items = {} - add_item: (name)=> + add_item: (name) => if @items[name] @items[name] += 1 else @@ -2798,7 +2804,7 @@ inv\add_item "pants" ```moonscript class Person clothes: [] - give_item: (name)=> + give_item: (name) => table.insert @clothes, name a = Person! @@ -2814,7 +2820,7 @@ print item for item in *a.clothes
 class Person
   clothes: []
-  give_item: (name)=>
+  give_item: (name) =>
     table.insert @clothes, name
 
 a = Person!
@@ -2850,7 +2856,7 @@ class Person
 ```moonscript
 class BackPack extends Inventory
   size: 10
-  add_item: (name)=>
+  add_item: (name) =>
     if #@items > size then error "背包已满"
     super name
 ```
@@ -2858,7 +2864,7 @@ class BackPack extends Inventory
 
 class BackPack extends Inventory
   size: 10
-  add_item: (name)=>
+  add_item: (name) =>
     if #@items > size then error "背包已满"
     super name
 
@@ -2873,7 +2879,7 @@ class BackPack extends Inventory ```moonscript class Shelf - @__inherited: (child)=> + @__inherited: (child) => print @__name, "被", child.__name, "继承" -- 将打印: Shelf 被 Cupboard 继承 @@ -2882,7 +2888,7 @@ class Cupboard extends Shelf
 class Shelf
-  @__inherited: (child)=>
+  @__inherited: (child) =>
     print @__name, "被", child.__name, "继承"
 
 -- 将打印: Shelf 被 Cupboard 继承
@@ -3065,7 +3071,7 @@ class Things
 ```moonscript
 class MoreThings
   secret = 123
-  log = (msg)-> print "LOG:", msg
+  log = (msg) -> print "LOG:", msg
 
   some_method: =>
     log "hello world: " .. secret
@@ -3074,7 +3080,7 @@ class MoreThings
 
 class MoreThings
   secret = 123
-  log = (msg)-> print "LOG:", msg
+  log = (msg) -> print "LOG:", msg
 
   some_method: =>
     log "hello world: " .. secret
@@ -3101,11 +3107,11 @@ assert @@ == self.__class
 例如,使用@@从实例方法快速创建同一类的新实例的方法:
 
 ```moonscript
-some_instance_method = (...)=> @@ ...
+some_instance_method = (...) => @@ ...
 ```
 
 
-some_instance_method = (...)=> @@ ...
+some_instance_method = (...) => @@ ...
 
@@ -3145,13 +3151,13 @@ class Something 你也可以使用这种语法为一个函数初始化传入对象的字段。 ```moonscript -new = (@fieldA, @fieldB)=> @ +new = (@fieldA, @fieldB) => @ obj = new {}, 123, "abc" print obj ```
-new = (@fieldA, @fieldB)=> @
+new = (@fieldA, @fieldB) => @
 obj = new {}, 123, "abc"
 print obj
 
@@ -3288,7 +3294,7 @@ file = with File "favorite_foods.txt" 或者… ```moonscript -create_person = (name, relatives)-> +create_person = (name, relatives) -> with Person! .name = name \add_relative relative for relative in *relatives @@ -3297,7 +3303,7 @@ me = create_person "Leaf", [dad, mother, sister] ```
-create_person = (name,  relatives)->
+create_person = (name,  relatives) ->
   with Person!
     .name = name
     \add_relative relative for relative in *relatives
@@ -3421,7 +3427,7 @@ my_object = {
   write: => print "值为:", @value
 }
 
-run_callback = (func)->
+run_callback = (func) ->
   print "运行回调..."
   func!
 
@@ -3440,7 +3446,7 @@ my_object = {
   write: => print "值为:", @value
 }
 
-run_callback = (func)->
+run_callback = (func) ->
   print "运行回调..."
   func!
 
@@ -3500,7 +3506,7 @@ print i -- 将打印 0
 ```moonscript
 i = 100
 
-my_func = (using nil)->
+my_func = (using nil) ->
   i = "hello" -- 这里创建了一个新的局部变量
 
 my_func!
@@ -3510,7 +3516,7 @@ print i -- 打印 100,i 没有受到影响
 
 i = 100
 
-my_func = (using nil)->
+my_func = (using nil) ->
   i = "hello" -- 这里创建了一个新的局部变量
 
 my_func!
@@ -3524,7 +3530,7 @@ using子句中可以填写多个用逗号分隔名称。指定可以访问和修
 tmp = 1213
 i, k = 100, 50
 
-my_func = (add using k, i)->
+my_func = (add using k, i) ->
   tmp = tmp + add -- 创建了一个新的局部tmp
   i += tmp
   k += tmp
@@ -3537,7 +3543,7 @@ print i, k -- 这些已经被更新
 tmp = 1213
 i, k = 100, 50
 
-my_func = (add using k, i)->
+my_func = (add using k, i) ->
   tmp = tmp + add -- 创建了一个新的局部tmp
   i += tmp
   k += tmp
-- 
cgit v1.2.3-55-g6feb