diff options
Diffstat (limited to 'doc/docs/doc/README.md')
-rwxr-xr-x | doc/docs/doc/README.md | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md index 7372eda..9b47d06 100755 --- a/doc/docs/doc/README.md +++ b/doc/docs/doc/README.md | |||
@@ -898,6 +898,7 @@ x = y = z = f! | |||
898 | ### Explicit Locals | 898 | ### Explicit Locals |
899 | ```moonscript | 899 | ```moonscript |
900 | do | 900 | do |
901 | local a = 1 | ||
901 | local * | 902 | local * |
902 | print "forward declare all variables as locals" | 903 | print "forward declare all variables as locals" |
903 | x = -> 1 + y + z | 904 | x = -> 1 + y + z |
@@ -905,6 +906,7 @@ do | |||
905 | global instance = Item\new! | 906 | global instance = Item\new! |
906 | 907 | ||
907 | do | 908 | do |
909 | local X = 1 | ||
908 | local ^ | 910 | local ^ |
909 | print "only forward declare upper case variables" | 911 | print "only forward declare upper case variables" |
910 | a = 1 | 912 | a = 1 |
@@ -913,6 +915,7 @@ do | |||
913 | <YueDisplay> | 915 | <YueDisplay> |
914 | <pre> | 916 | <pre> |
915 | do | 917 | do |
918 | local a = 1 | ||
916 | local * | 919 | local * |
917 | print "forward declare all variables as locals" | 920 | print "forward declare all variables as locals" |
918 | x = -> 1 + y + z | 921 | x = -> 1 + y + z |
@@ -920,6 +923,7 @@ do | |||
920 | global instance = Item\new! | 923 | global instance = Item\new! |
921 | 924 | ||
922 | do | 925 | do |
926 | local X = 1 | ||
923 | local ^ | 927 | local ^ |
924 | print "only forward declare upper case variables" | 928 | print "only forward declare upper case variables" |
925 | a = 1 | 929 | a = 1 |
@@ -930,12 +934,14 @@ do | |||
930 | ### Explicit Globals | 934 | ### Explicit Globals |
931 | ```moonscript | 935 | ```moonscript |
932 | do | 936 | do |
937 | global a = 1 | ||
933 | global * | 938 | global * |
934 | print "declare all variables as globals" | 939 | print "declare all variables as globals" |
935 | x = -> 1 + y + z | 940 | x = -> 1 + y + z |
936 | y, z = 2, 3 | 941 | y, z = 2, 3 |
937 | 942 | ||
938 | do | 943 | do |
944 | global X = 1 | ||
939 | global ^ | 945 | global ^ |
940 | print "only declare upper case variables as globals" | 946 | print "only declare upper case variables as globals" |
941 | a = 1 | 947 | a = 1 |
@@ -945,12 +951,14 @@ do | |||
945 | <YueDisplay> | 951 | <YueDisplay> |
946 | <pre> | 952 | <pre> |
947 | do | 953 | do |
954 | global a = 1 | ||
948 | global * | 955 | global * |
949 | print "declare all variables as globals" | 956 | print "declare all variables as globals" |
950 | x = -> 1 + y + z | 957 | x = -> 1 + y + z |
951 | y, z = 2, 3 | 958 | y, z = 2, 3 |
952 | 959 | ||
953 | do | 960 | do |
961 | global X = 1 | ||
954 | global ^ | 962 | global ^ |
955 | print "only declare upper case variables as globals" | 963 | print "only declare upper case variables as globals" |
956 | a = 1 | 964 | a = 1 |
@@ -2544,6 +2552,35 @@ msg = switch math.random(1, 5) | |||
2544 | </pre> | 2552 | </pre> |
2545 | </YueDisplay> | 2553 | </YueDisplay> |
2546 | 2554 | ||
2555 | If you want to write code with one less indent when writing a switch statement, you can put the first when clause on the statement start line, and then all other clauses can be written with one less indent. | ||
2556 | |||
2557 | ```moonscript | ||
2558 | switch math.random(1, 5) | ||
2559 | when 1 | ||
2560 | print "you are lucky" -- two indents | ||
2561 | else | ||
2562 | print "not so lucky" | ||
2563 | |||
2564 | switch math.random(1, 5) when 1 | ||
2565 | print "you are lucky" -- one indent | ||
2566 | else | ||
2567 | print "not so lucky" | ||
2568 | ``` | ||
2569 | <YueDisplay> | ||
2570 | <pre> | ||
2571 | switch math.random(1, 5) | ||
2572 | when 1 | ||
2573 | print "you are lucky" -- two indents | ||
2574 | else | ||
2575 | print "not so lucky" | ||
2576 | |||
2577 | switch math.random(1, 5) when 1 | ||
2578 | print "you are lucky" -- one indent | ||
2579 | else | ||
2580 | print "not so lucky" | ||
2581 | </pre> | ||
2582 | </YueDisplay> | ||
2583 | |||
2547 | It is worth noting the order of the case comparison expression. The case’s expression is on the left hand side. This can be useful if the case’s expression wants to overwrite how the comparison is done by defining an eq metamethod. | 2584 | It is worth noting the order of the case comparison expression. The case’s expression is on the left hand side. This can be useful if the case’s expression wants to overwrite how the comparison is done by defining an eq metamethod. |
2548 | 2585 | ||
2549 | ### Table Matching | 2586 | ### Table Matching |