From 3c8531d33e1de84a7c5f70e0a4cb3d95e7a44c0a Mon Sep 17 00:00:00 2001 From: Li Jin Date: Thu, 25 Dec 2025 09:38:59 +0800 Subject: Updated docs. [skip CI] --- doc/docs/doc/README.md | 98 +++++++++++++++++++++++------------------------ doc/docs/zh/doc/README.md | 98 +++++++++++++++++++++++------------------------ 2 files changed, 98 insertions(+), 98 deletions(-) diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index d2f838d..0047a3f 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md @@ -1528,55 +1528,6 @@ print ok, count, first -### Named Varargs - -You can use the `(...t) ->` syntax to automatically store varargs into a named table. This table will contain all passed arguments (including `nil` values), and the `n` field of the table will store the actual number of arguments passed (including `nil` values). - -```moonscript -f = (...t) -> - print "argument count:", t.n - print "table length:", #t - for i = 1, t.n - print t[i] - -f 1, 2, 3 -f "a", "b", "c", "d" -f! - --- Handling cases with nil values -process = (...args) -> - sum = 0 - for i = 1, args.n - if args[i] != nil and type(args[i]) == "number" - sum += args[i] - sum - -process 1, nil, 3, nil, 5 -``` - -
-f = (...t) ->
-  print "argument count:", t.n
-  print "table length:", #t
-  for i = 1, t.n
-    print t[i]
-
-f 1, 2, 3
-f "a", "b", "c", "d"
-f!
-
--- Handling cases with nil values
-process = (...args) ->
-  sum = 0
-  for i = 1, args.n
-    if args[i] != nil and type(args[i]) == "number"
-      sum += args[i]
-  sum
-
-process 1, nil, 3, nil, 5
-
-
- ## Whitespace YueScript is a whitespace significant language. You have to write some code block in the same indent with space **' '** or tab **'\t'** like function body, value list and some control blocks. And expressions containing different whitespaces might mean different things. Tab is treated like 4 space, but it's better not mix the use of spaces and tabs. @@ -2277,6 +2228,55 @@ findFirstEven = (list) -> The only difference is that you can move the final return expression before the `->` or `=>` token to indicate the function’s implicit return value as the last statement. This way, even in functions with multiple nested loops or conditional branches, you no longer need to write a trailing return expression at the end of the function body, making the logic structure more straightforward and easier to follow. +### Named Varargs + +You can use the `(...t) ->` syntax to automatically store varargs into a named table. This table will contain all passed arguments (including `nil` values), and the `n` field of the table will store the actual number of arguments passed (including `nil` values). + +```moonscript +f = (...t) -> + print "argument count:", t.n + print "table length:", #t + for i = 1, t.n + print t[i] + +f 1, 2, 3 +f "a", "b", "c", "d" +f! + +-- Handling cases with nil values +process = (...args) -> + sum = 0 + for i = 1, args.n + if args[i] != nil and type(args[i]) == "number" + sum += args[i] + sum + +process 1, nil, 3, nil, 5 +``` + +
+f = (...t) ->
+  print "argument count:", t.n
+  print "table length:", #t
+  for i = 1, t.n
+    print t[i]
+
+f 1, 2, 3
+f "a", "b", "c", "d"
+f!
+
+-- Handling cases with nil values
+process = (...args) ->
+  sum = 0
+  for i = 1, args.n
+    if args[i] != nil and type(args[i]) == "number"
+      sum += args[i]
+  sum
+
+process 1, nil, 3, nil, 5
+
+
+ ## Backcalls Backcalls are used for unnesting callbacks. They are defined using arrows pointed to the left as the last parameter by default filling in a function call. All the syntax is mostly the same as regular arrow functions except that it is just pointing the other way and the function body does not require indent. diff --git a/doc/docs/zh/doc/README.md b/doc/docs/zh/doc/README.md index 34d577c..de5dff1 100755 --- a/doc/docs/zh/doc/README.md +++ b/doc/docs/zh/doc/README.md @@ -1526,55 +1526,6 @@ print ok, count, first -### 命名变长参数 - -你可以使用 `(...t) ->` 语法来将变长参数自动存储到一个命名表中。这个表会包含所有传入的参数(包括 `nil` 值),并且会在表的 `n` 字段中存储实际传入的参数个数(包括 `nil` 值在内的个数)。 - -```moonscript -f = (...t) -> - print "参数个数:", t.n - print "表长度:", #t - for i = 1, t.n - print t[i] - -f 1, 2, 3 -f "a", "b", "c", "d" -f! - --- 处理包含 nil 的情况 -process = (...args) -> - sum = 0 - for i = 1, args.n - if args[i] != nil and type(args[i]) == "number" - sum += args[i] - sum - -process 1, nil, 3, nil, 5 -``` - -
-f = (...t) ->
-  print "参数个数:", t.n
-  print "表长度:", #t
-  for i = 1, t.n
-    print t[i]
-
-f 1, 2, 3
-f "a", "b", "c", "d"
-f!
-
--- 处理包含 nil 的情况
-process = (...args) ->
-  sum = 0
-  for i = 1, args.n
-    if args[i] != nil and type(args[i]) == "number"
-      sum += args[i]
-  sum
-
-process 1, nil, 3, nil, 5
-
-
- ## 空白 月之脚本是一个对空白敏感的语言。你必须在相同的缩进中使用空格 **' '** 或制表符 **'\t'** 来编写一些代码块,如函数体、值列表和一些控制块。包含不同空白的表达式可能意味着不同的事情。制表符被视为4个空格,但最好不要混合使用空格和制表符。 @@ -2237,6 +2188,55 @@ findFirstEven = (list) -> 唯一的区别在于:你可以将函数的返回值表达式提前写在 `->` 或 `=>` 前,用以指示该函数应隐式返回该表达式的值。这样即使在多层循环或条件判断的场景下,也无需编写尾行悬挂的返回表达式,逻辑结构会更加直观清晰。 +### 命名变长参数 + +你可以使用 `(...t) ->` 语法来将变长参数自动存储到一个命名表中。这个表会包含所有传入的参数(包括 `nil` 值),并且会在表的 `n` 字段中存储实际传入的参数个数(包括 `nil` 值在内的个数)。 + +```moonscript +f = (...t) -> + print "参数个数:", t.n + print "表长度:", #t + for i = 1, t.n + print t[i] + +f 1, 2, 3 +f "a", "b", "c", "d" +f! + +-- 处理包含 nil 的情况 +process = (...args) -> + sum = 0 + for i = 1, args.n + if args[i] != nil and type(args[i]) == "number" + sum += args[i] + sum + +process 1, nil, 3, nil, 5 +``` + +
+f = (...t) ->
+  print "参数个数:", t.n
+  print "表长度:", #t
+  for i = 1, t.n
+    print t[i]
+
+f 1, 2, 3
+f "a", "b", "c", "d"
+f!
+
+-- 处理包含 nil 的情况
+process = (...args) ->
+  sum = 0
+  for i = 1, args.n
+    if args[i] != nil and type(args[i]) == "number"
+      sum += args[i]
+  sum
+
+process 1, nil, 3, nil, 5
+
+
+ ## 反向回调 反向回调用于减少函数回调的嵌套。它们使用指向左侧的箭头,并且默认会被定义为传入后续函数调用的最后一个参数。它的语法大部分与常规箭头函数相同,只是它指向另一方向,并且后续的函数体不需要进行缩进。 -- cgit v1.2.3-55-g6feb