You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/docs/doc/README.md
+49-49Lines changed: 49 additions & 49 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1528,55 +1528,6 @@ print ok, count, first
1528
1528
</pre>
1529
1529
</YueDisplay>
1530
1530
1531
-
### Named Varargs
1532
-
1533
-
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).
1534
-
1535
-
```moonscript
1536
-
f = (...t) ->
1537
-
print "argument count:", t.n
1538
-
print "table length:", #t
1539
-
for i = 1, t.n
1540
-
print t[i]
1541
-
1542
-
f 1, 2, 3
1543
-
f "a", "b", "c", "d"
1544
-
f!
1545
-
1546
-
-- Handling cases with nil values
1547
-
process = (...args) ->
1548
-
sum = 0
1549
-
for i = 1, args.n
1550
-
if args[i] != nil and type(args[i]) == "number"
1551
-
sum += args[i]
1552
-
sum
1553
-
1554
-
process 1, nil, 3, nil, 5
1555
-
```
1556
-
<YueDisplay>
1557
-
<pre>
1558
-
f = (...t) ->
1559
-
print "argument count:", t.n
1560
-
print "table length:", #t
1561
-
for i = 1, t.n
1562
-
print t[i]
1563
-
1564
-
f 1, 2, 3
1565
-
f "a", "b", "c", "d"
1566
-
f!
1567
-
1568
-
-- Handling cases with nil values
1569
-
process = (...args) ->
1570
-
sum = 0
1571
-
for i = 1, args.n
1572
-
if args[i] != nil and type(args[i]) == "number"
1573
-
sum += args[i]
1574
-
sum
1575
-
1576
-
process 1, nil, 3, nil, 5
1577
-
</pre>
1578
-
</YueDisplay>
1579
-
1580
1531
## Whitespace
1581
1532
1582
1533
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) ->
2277
2228
2278
2229
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.
2279
2230
2231
+
### Named Varargs
2232
+
2233
+
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).
2234
+
2235
+
```moonscript
2236
+
f = (...t) ->
2237
+
print "argument count:", t.n
2238
+
print "table length:", #t
2239
+
for i = 1, t.n
2240
+
print t[i]
2241
+
2242
+
f 1, 2, 3
2243
+
f "a", "b", "c", "d"
2244
+
f!
2245
+
2246
+
-- Handling cases with nil values
2247
+
process = (...args) ->
2248
+
sum = 0
2249
+
for i = 1, args.n
2250
+
if args[i] != nil and type(args[i]) == "number"
2251
+
sum += args[i]
2252
+
sum
2253
+
2254
+
process 1, nil, 3, nil, 5
2255
+
```
2256
+
<YueDisplay>
2257
+
<pre>
2258
+
f = (...t) ->
2259
+
print "argument count:", t.n
2260
+
print "table length:", #t
2261
+
for i = 1, t.n
2262
+
print t[i]
2263
+
2264
+
f 1, 2, 3
2265
+
f "a", "b", "c", "d"
2266
+
f!
2267
+
2268
+
-- Handling cases with nil values
2269
+
process = (...args) ->
2270
+
sum = 0
2271
+
for i = 1, args.n
2272
+
if args[i] != nil and type(args[i]) == "number"
2273
+
sum += args[i]
2274
+
sum
2275
+
2276
+
process 1, nil, 3, nil, 5
2277
+
</pre>
2278
+
</YueDisplay>
2279
+
2280
2280
## Backcalls
2281
2281
2282
2282
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.
0 commit comments