aboutsummaryrefslogtreecommitdiff
path: root/doc/docs/doc/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'doc/docs/doc/README.md')
-rwxr-xr-xdoc/docs/doc/README.md112
1 files changed, 56 insertions, 56 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index aaeea2d..54c6b72 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -30,7 +30,7 @@ inventory =
30 count: 3 30 count: 3
31 31
32-- pipe operator 32-- pipe operator
33{1, 2, 3} 33[1, 2, 3]
34 |> map (x)-> x * 2 34 |> map (x)-> x * 2
35 |> filter (x)-> x > 4 35 |> filter (x)-> x > 4
36 |> reduce 0, (a, b)-> a + b 36 |> reduce 0, (a, b)-> a + b
@@ -62,7 +62,7 @@ inventory =
62 count: 3 62 count: 3
63 63
64-- pipe operator 64-- pipe operator
65{1, 2, 3} 65[1, 2, 3]
66 |> map (x)-> x * 2 66 |> map (x)-> x * 2
67 |> filter (x)-> x > 4 67 |> filter (x)-> x > 4
68 |> reduce 0, (a, b)-> a + b 68 |> reduce 0, (a, b)-> a + b
@@ -339,7 +339,7 @@ import "utils" as {
339 $, -- symbol to import all macros 339 $, -- symbol to import all macros
340 $foreach: $each -- rename macro $foreach to $each 340 $foreach: $each -- rename macro $foreach to $each
341} 341}
342{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ 342[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
343``` 343```
344<YueDisplay> 344<YueDisplay>
345<pre> 345<pre>
@@ -355,7 +355,7 @@ import "utils" as {
355 $, -- symbol to import all macros 355 $, -- symbol to import all macros
356 $foreach: $each -- rename macro $foreach to $each 356 $foreach: $each -- rename macro $foreach to $each
357} 357}
358{1, 2, 3} |> $map(_ * 2) |> $filter(_ > 4) |> $each print _ 358[1, 2, 3] |> $map(_ * 2) |> $filter(_ > 4) |> $each print _
359]] 359]]
360</pre> 360</pre>
361</YueDisplay> 361</YueDisplay>
@@ -467,12 +467,12 @@ The middle expression is only evaluated once, rather than twice as it would be i
467The **[] =** operator is used to append values to tables. 467The **[] =** operator is used to append values to tables.
468 468
469```moonscript 469```moonscript
470tab = {} 470tab = []
471tab[] = "Value" 471tab[] = "Value"
472``` 472```
473<YueDisplay> 473<YueDisplay>
474<pre> 474<pre>
475tab = {} 475tab = []
476tab[] = "Value" 476tab[] = "Value"
477</pre> 477</pre>
478</YueDisplay> 478</YueDisplay>
@@ -1106,27 +1106,27 @@ This also works with nested data structures as well:
1106 1106
1107```moonscript 1107```moonscript
1108obj2 = { 1108obj2 = {
1109 numbers: {1,2,3,4} 1109 numbers: [1, 2, 3, 4]
1110 properties: { 1110 properties: {
1111 color: "green" 1111 color: "green"
1112 height: 13.5 1112 height: 13.5
1113 } 1113 }
1114} 1114}
1115 1115
1116{numbers: {first, second}} = obj2 1116{numbers: [first, second]} = obj2
1117print first, second, color 1117print first, second, color
1118``` 1118```
1119<YueDisplay> 1119<YueDisplay>
1120<pre> 1120<pre>
1121obj2 = { 1121obj2 = {
1122 numbers: {1,2,3,4} 1122 numbers: [1, 2, 3, 4]
1123 properties: { 1123 properties: {
1124 color: "green" 1124 color: "green"
1125 height: 13.5 1125 height: 13.5
1126 } 1126 }
1127} 1127}
1128 1128
1129{numbers: {first, second}} = obj2 1129{numbers: [first, second]} = obj2
1130print first, second, color 1130print first, second, color
1131</pre> 1131</pre>
1132</YueDisplay> 1132</YueDisplay>
@@ -1135,7 +1135,7 @@ If the destructuring statement is complicated, feel free to spread it out over a
1135 1135
1136```moonscript 1136```moonscript
1137{ 1137{
1138 numbers: {first, second} 1138 numbers: [first, second]
1139 properties: { 1139 properties: {
1140 color: color 1140 color: color
1141 } 1141 }
@@ -1144,7 +1144,7 @@ If the destructuring statement is complicated, feel free to spread it out over a
1144<YueDisplay> 1144<YueDisplay>
1145<pre> 1145<pre>
1146{ 1146{
1147 numbers: {first, second} 1147 numbers: [first, second]
1148 properties: { 1148 properties: {
1149 color: color 1149 color: color
1150 } 1150 }
@@ -1188,11 +1188,11 @@ You can write default values while doing destructuring like:
1188You can use `_` as placeholder when doing a list destructuring: 1188You can use `_` as placeholder when doing a list destructuring:
1189 1189
1190```moonscript 1190```moonscript
1191{_, two, _, four} = items 1191[_, two, _, four] = items
1192``` 1192```
1193<YueDisplay> 1193<YueDisplay>
1194<pre> 1194<pre>
1195{_, two, _, four} = items 1195[_, two, _, four] = items
1196</pre> 1196</pre>
1197</YueDisplay> 1197</YueDisplay>
1198 1198
@@ -1201,22 +1201,22 @@ You can use `_` as placeholder when doing a list destructuring:
1201Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop: 1201Destructuring can also show up in places where an assignment implicitly takes place. An example of this is a for loop:
1202 1202
1203```moonscript 1203```moonscript
1204tuples = { 1204tuples = [
1205 {"hello", "world"} 1205 ["hello", "world"]
1206 {"egg", "head"} 1206 ["egg", "head"]
1207} 1207]
1208 1208
1209for {left, right} in *tuples 1209for [left, right] in *tuples
1210 print left, right 1210 print left, right
1211``` 1211```
1212<YueDisplay> 1212<YueDisplay>
1213<pre> 1213<pre>
1214tuples = { 1214tuples = [
1215 {"hello", "world"} 1215 ["hello", "world"]
1216 {"egg", "head"} 1216 ["egg", "head"]
1217} 1217]
1218 1218
1219for {left, right} in *tuples 1219for [left, right] in *tuples
1220 print left, right 1220 print left, right
1221</pre> 1221</pre>
1222</YueDisplay> 1222</YueDisplay>
@@ -1275,7 +1275,7 @@ print "OK"
1275 1275
1276You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way. 1276You can assign the results returned from a function to a varargs symbol `...`. And then access its content using the Lua way.
1277```moonscript 1277```moonscript
1278list = {1, 2, 3, 4, 5} 1278list = [1, 2, 3, 4, 5]
1279fn = (ok) -> ok, table.unpack list 1279fn = (ok) -> ok, table.unpack list
1280ok, ... = fn true 1280ok, ... = fn true
1281count = select '#', ... 1281count = select '#', ...
@@ -1284,7 +1284,7 @@ print ok, count, first
1284``` 1284```
1285<YueDisplay> 1285<YueDisplay>
1286<pre> 1286<pre>
1287list = {1, 2, 3, 4, 5} 1287list = [1, 2, 3, 4, 5]
1288fn = (ok) -> ok, table.unpack list 1288fn = (ok) -> ok, table.unpack list
1289ok, ... = fn true 1289ok, ... = fn true
1290count = select '#', ... 1290count = select '#', ...
@@ -1731,36 +1731,36 @@ my_func 5, 6, 7,
1731Because tables also use the comma as a delimiter, this indentation syntax is helpful for letting values be part of the argument list instead of being part of the table. 1731Because tables also use the comma as a delimiter, this indentation syntax is helpful for letting values be part of the argument list instead of being part of the table.
1732 1732
1733```moonscript 1733```moonscript
1734x = { 1734x = [
1735 1, 2, 3, 4, a_func 4, 5, 1735 1, 2, 3, 4, a_func 4, 5,
1736 5, 6, 1736 5, 6,
1737 8, 9, 10 1737 8, 9, 10
1738} 1738]
1739``` 1739```
1740<YueDisplay> 1740<YueDisplay>
1741<pre> 1741<pre>
1742x = { 1742x = [
1743 1, 2, 3, 4, a_func 4, 5, 1743 1, 2, 3, 4, a_func 4, 5,
1744 5, 6, 1744 5, 6,
1745 8, 9, 10 1745 8, 9, 10
1746} 1746]
1747</pre> 1747</pre>
1748</YueDisplay> 1748</YueDisplay>
1749 1749
1750Although uncommon, notice how we can give a deeper indentation for function arguments if we know we will be using a lower indentation further on. 1750Although uncommon, notice how we can give a deeper indentation for function arguments if we know we will be using a lower indentation further on.
1751 1751
1752```moonscript 1752```moonscript
1753y = { my_func 1, 2, 3, 1753y = [ my_func 1, 2, 3,
1754 4, 5, 1754 4, 5,
1755 5, 6, 7 1755 5, 6, 7
1756} 1756]
1757``` 1757```
1758<YueDisplay> 1758<YueDisplay>
1759<pre> 1759<pre>
1760y = { my_func 1, 2, 3, 1760y = [ my_func 1, 2, 3,
1761 4, 5, 1761 4, 5,
1762 5, 6, 7 1762 5, 6, 7
1763} 1763]
1764</pre> 1764</pre>
1765</YueDisplay> 1765</YueDisplay>
1766 1766
@@ -1826,12 +1826,12 @@ print @value
1826You can specify a placeholder for where you want the backcall function to go as a parameter. 1826You can specify a placeholder for where you want the backcall function to go as a parameter.
1827 1827
1828```moonscript 1828```moonscript
1829(x) <- map _, {1, 2, 3} 1829(x) <- map _, [1, 2, 3]
1830x * 2 1830x * 2
1831``` 1831```
1832<YueDisplay> 1832<YueDisplay>
1833<pre> 1833<pre>
1834(x) <- map _, {1, 2, 3} 1834(x) <- map _, [1, 2, 3]
1835x * 2 1835x * 2
1836</pre> 1836</pre>
1837</YueDisplay> 1837</YueDisplay>
@@ -1862,11 +1862,11 @@ print result, msg
1862Like in Lua, tables are delimited in curly braces. 1862Like in Lua, tables are delimited in curly braces.
1863 1863
1864```moonscript 1864```moonscript
1865some_values = { 1, 2, 3, 4 } 1865some_values = [1, 2, 3, 4]
1866``` 1866```
1867<YueDisplay> 1867<YueDisplay>
1868<pre> 1868<pre>
1869some_values = { 1, 2, 3, 4 } 1869some_values = [1, 2, 3, 4]
1870</pre> 1870</pre>
1871</YueDisplay> 1871</YueDisplay>
1872 1872
@@ -1895,14 +1895,14 @@ The curly braces can be left off if a single table of key value pairs is being a
1895profile = 1895profile =
1896 height: "4 feet", 1896 height: "4 feet",
1897 shoe_size: 13, 1897 shoe_size: 13,
1898 favorite_foods: {"ice cream", "donuts"} 1898 favorite_foods: ["ice cream", "donuts"]
1899``` 1899```
1900<YueDisplay> 1900<YueDisplay>
1901<pre> 1901<pre>
1902profile = 1902profile =
1903 height: "4 feet", 1903 height: "4 feet",
1904 shoe_size: 13, 1904 shoe_size: 13,
1905 favorite_foods: {"ice cream", "donuts"} 1905 favorite_foods: ["ice cream", "donuts"]
1906</pre> 1906</pre>
1907</YueDisplay> 1907</YueDisplay>
1908 1908
@@ -1998,13 +1998,13 @@ t = {
1998Lua tables have both an array part and a hash part, but sometimes you want to make a semantic distinction between array and hash usage when writing Lua tables. Then you can write Lua table with **[ ]** instead of **{ }** to represent an array table and writing any key value pair in a list table won't be allowed. 1998Lua tables have both an array part and a hash part, but sometimes you want to make a semantic distinction between array and hash usage when writing Lua tables. Then you can write Lua table with **[ ]** instead of **{ }** to represent an array table and writing any key value pair in a list table won't be allowed.
1999 1999
2000```moonscript 2000```moonscript
2001some_values = [ 1, 2, 3, 4 ] 2001some_values = [1, 2, 3, 4]
2002list_with_one_element = [ 1, ] 2002list_with_one_element = [1, ]
2003``` 2003```
2004<YueDisplay> 2004<YueDisplay>
2005<pre> 2005<pre>
2006some_values = [ 1, 2, 3, 4 ] 2006some_values = [1, 2, 3, 4]
2007list_with_one_element = [ 1, ] 2007list_with_one_element = [1, ]
2008</pre> 2008</pre>
2009</YueDisplay> 2009</YueDisplay>
2010 2010
@@ -2137,12 +2137,12 @@ The key-value tuple in a table comprehension can also come from a single express
2137In this example we convert an array of pairs to a table where the first item in the pair is the key and the second is the value. 2137In this example we convert an array of pairs to a table where the first item in the pair is the key and the second is the value.
2138 2138
2139```moonscript 2139```moonscript
2140tuples = {{"hello", "world"}, {"foo", "bar"}} 2140tuples = [ ["hello", "world"], ["foo", "bar"]]
2141tbl = {unpack tuple for tuple in *tuples} 2141tbl = {unpack tuple for tuple in *tuples}
2142``` 2142```
2143<YueDisplay> 2143<YueDisplay>
2144<pre> 2144<pre>
2145tuples = { {"hello", "world"}, {"foo", "bar"} } 2145tuples = [ ["hello", "world"], ["foo", "bar"]]
2146tbl = {unpack tuple for tuple in *tuples} 2146tbl = {unpack tuple for tuple in *tuples}
2147</pre> 2147</pre>
2148</YueDisplay> 2148</YueDisplay>
@@ -2371,14 +2371,14 @@ while i < 10
2371continue can also be used with loop expressions to prevent that iteration from accumulating into the result. This examples filters the array table into just even numbers: 2371continue can also be used with loop expressions to prevent that iteration from accumulating into the result. This examples filters the array table into just even numbers:
2372 2372
2373```moonscript 2373```moonscript
2374my_numbers = {1, 2, 3, 4, 5, 6} 2374my_numbers = [1, 2, 3, 4, 5, 6]
2375odds = for x in *my_numbers 2375odds = for x in *my_numbers
2376 continue if x % 2 == 1 2376 continue if x % 2 == 1
2377 x 2377 x
2378``` 2378```
2379<YueDisplay> 2379<YueDisplay>
2380<pre> 2380<pre>
2381my_numbers = {1, 2, 3, 4, 5, 6} 2381my_numbers = [1, 2, 3, 4, 5, 6]
2382odds = for x in *my_numbers 2382odds = for x in *my_numbers
2383 continue if x % 2 == 1 2383 continue if x % 2 == 1
2384 x 2384 x
@@ -2492,7 +2492,7 @@ You can write range checking code with an `in-expression`.
2492```moonscript 2492```moonscript
2493a = 5 2493a = 5
2494 2494
2495if a in {1, 3, 5, 7} 2495if a in [1, 3, 5, 7]
2496 print "checking equality with discrete values" 2496 print "checking equality with discrete values"
2497 2497
2498if a in list 2498if a in list
@@ -2502,7 +2502,7 @@ if a in list
2502<pre> 2502<pre>
2503a = 5 2503a = 5
2504 2504
2505if a in {1, 3, 5, 7} 2505if a in [1, 3, 5, 7]
2506 print "checking equality with discrete values" 2506 print "checking equality with discrete values"
2507 2507
2508if a in list 2508if a in list
@@ -2780,7 +2780,7 @@ Consider the example below, the clothes property is shared amongst all instances
2780 2780
2781```moonscript 2781```moonscript
2782class Person 2782class Person
2783 clothes: {} 2783 clothes: []
2784 give_item: (name)=> 2784 give_item: (name)=>
2785 table.insert @clothes, name 2785 table.insert @clothes, name
2786 2786
@@ -2796,7 +2796,7 @@ print item for item in *a.clothes
2796<YueDisplay> 2796<YueDisplay>
2797<pre> 2797<pre>
2798class Person 2798class Person
2799 clothes: {} 2799 clothes: []
2800 give_item: (name)=> 2800 give_item: (name)=>
2801 table.insert @clothes, name 2801 table.insert @clothes, name
2802 2802
@@ -2816,13 +2816,13 @@ The proper way to avoid this problem is to create the mutable state of the objec
2816```moonscript 2816```moonscript
2817class Person 2817class Person
2818 new: => 2818 new: =>
2819 @clothes = {} 2819 @clothes = []
2820``` 2820```
2821<YueDisplay> 2821<YueDisplay>
2822<pre> 2822<pre>
2823class Person 2823class Person
2824 new: => 2824 new: =>
2825 @clothes = {} 2825 @clothes = []
2826</pre> 2826</pre>
2827</YueDisplay> 2827</YueDisplay>
2828 2828
@@ -3278,7 +3278,7 @@ create_person = (name, relatives)->
3278 .name = name 3278 .name = name
3279 \add_relative relative for relative in *relatives 3279 \add_relative relative for relative in *relatives
3280 3280
3281me = create_person "Leaf", {dad, mother, sister} 3281me = create_person "Leaf", [dad, mother, sister]
3282``` 3282```
3283<YueDisplay> 3283<YueDisplay>
3284<pre> 3284<pre>
@@ -3287,7 +3287,7 @@ create_person = (name, relatives)->
3287 .name = name 3287 .name = name
3288 \add_relative relative for relative in *relatives 3288 \add_relative relative for relative in *relatives
3289 3289
3290me = create_person "Leaf", {dad, mother, sister} 3290me = create_person "Leaf", [dad, mother, sister]
3291</pre> 3291</pre>
3292</YueDisplay> 3292</YueDisplay>
3293 3293