aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorLi Jin <dragon-fly@qq.com>2023-06-07 11:53:01 +0800
committerLi Jin <dragon-fly@qq.com>2023-06-07 11:53:01 +0800
commit5d246757285a437401347dd6a1a1f8d3cf61e08c (patch)
tree20acad2b362f78245b61e92e003be7cdebecbb28 /doc
parent2a3e50752ade96c3b5d6b1103937bef0f6b31157 (diff)
downloadyuescript-5d246757285a437401347dd6a1a1f8d3cf61e08c.tar.gz
yuescript-5d246757285a437401347dd6a1a1f8d3cf61e08c.tar.bz2
yuescript-5d246757285a437401347dd6a1a1f8d3cf61e08c.zip
update docs.v0.17.0
Diffstat (limited to 'doc')
-rwxr-xr-xdoc/docs/doc/README.md93
1 files changed, 93 insertions, 0 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index 3a7b1e7..2c21a37 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -2355,6 +2355,52 @@ print "You're lucky!" unless math.random! > 0.1
2355</pre> 2355</pre>
2356</YueDisplay> 2356</YueDisplay>
2357 2357
2358### In Expression
2359
2360You can write range checking code with an `in-expression`.
2361
2362```moonscript
2363a = 5
2364
2365if a in [1, 10]
2366 print "a is in range from 1 to 10"
2367
2368if a not in [1, 10]
2369 print "a is not in range from 1 to 10"
2370
2371if a in (0, 11)
2372 print "a is between 0 and 11 with open intervals"
2373
2374if a in {1, 3, 5, 7}
2375 print "checking equality with discrete values"
2376```
2377<YueDisplay>
2378<pre>
2379a = 5
2380
2381if a in [1, 10]
2382 print "a is in range from 1 to 10"
2383
2384if a not in [1, 10]
2385 print "a is not in range from 1 to 10"
2386
2387if a in (0, 11)
2388 print "a is between 0 and 11 with open intervals"
2389
2390if a in {1, 3, 5, 7}
2391 print "checking equality with discrete values"
2392</pre>
2393</YueDisplay>
2394
2395```moonscript
2396print "You're lucky!" unless math.random! > 0.1
2397```
2398<YueDisplay>
2399<pre>
2400print "You're lucky!" unless math.random! > 0.1
2401</pre>
2402</YueDisplay>
2403
2358## Line Decorators 2404## Line Decorators
2359 2405
2360For convenience, the for loop and if statement can be applied to single statements at the end of the line: 2406For convenience, the for loop and if statement can be applied to single statements at the end of the line:
@@ -2525,6 +2571,53 @@ switch item
2525</pre> 2571</pre>
2526</YueDisplay> 2572</YueDisplay>
2527 2573
2574### Range Matching
2575
2576You can do range matching in a switch when clause using `In` expressions.
2577
2578```moonscript
2579value = 5
2580
2581switch item
2582 -- range checking with closed interval
2583 when in [1, 3]
2584 print "1 <= value <= 3"
2585
2586 -- range checking with open and closed interval
2587 when in (6, 8]
2588 print "6 < value <= 8"
2589
2590 -- not in range checking
2591 when not in [1, 10)
2592 print "not (1 < value <= 10)"
2593
2594 -- checking discrete values
2595 when in {11, 21, 99}
2596 print "value is 11, 21 or 99"
2597```
2598<YueDisplay>
2599<pre>
2600value = 5
2601
2602switch item
2603 -- range checking with closed interval
2604 when in [1, 3]
2605 print "1 <= value <= 3"
2606
2607 -- range checking with open and closed interval
2608 when in (6, 8]
2609 print "6 < value <= 8"
2610
2611 -- not in range checking
2612 when not in [1, 10)
2613 print "not (1 < value <= 10)"
2614
2615 -- checking discrete values
2616 when in {11, 21, 99}
2617 print "value is 11, 21 or 99"
2618</pre>
2619</YueDisplay>
2620
2528## Object Oriented Programming 2621## Object Oriented Programming
2529 2622
2530In these examples, the generated Lua code may appear overwhelming. It is best to focus on the meaning of the Yuescript code at first, then look into the Lua code if you wish to know the implementation details. 2623In these examples, the generated Lua code may appear overwhelming. It is best to focus on the meaning of the Yuescript code at first, then look into the Lua code if you wish to know the implementation details.