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.md22
1 files changed, 11 insertions, 11 deletions
diff --git a/doc/docs/doc/README.md b/doc/docs/doc/README.md
index 54c6b72..041120b 100755
--- a/doc/docs/doc/README.md
+++ b/doc/docs/doc/README.md
@@ -1225,32 +1225,32 @@ We know each element in the array table is a two item tuple, so we can unpack it
1225 1225
1226## If Assignment 1226## If Assignment
1227 1227
1228if and elseif blocks can take an assignment in place of a conditional expression. Upon evaluating the conditional, the assignment will take place and the value that was assigned to will be used as the conditional expression. The assigned variable is only in scope for the body of the conditional, meaning it is never available if the value is not truthy. 1228`if` and `elseif` blocks can take an assignment in place of a conditional expression. Upon evaluating the conditional, the assignment will take place and the value that was assigned to will be used as the conditional expression. The assigned variable is only in scope for the body of the conditional, meaning it is never available if the value is not truthy. And you have to use "the walrus operator" `:=` instead of `=` to do assignment.
1229 1229
1230```moonscript 1230```moonscript
1231if user = database.find_user "moon" 1231if user := database.find_user "moon"
1232 print user.name 1232 print user.name
1233``` 1233```
1234<YueDisplay> 1234<YueDisplay>
1235<pre> 1235<pre>
1236if user = database.find_user "moon" 1236if user := database.find_user "moon"
1237 print user.name 1237 print user.name
1238</pre> 1238</pre>
1239</YueDisplay> 1239</YueDisplay>
1240 1240
1241```moonscript 1241```moonscript
1242if hello = os.getenv "hello" 1242if hello := os.getenv "hello"
1243 print "You have hello", hello 1243 print "You have hello", hello
1244elseif world = os.getenv "world" 1244elseif world := os.getenv "world"
1245 print "you have world", world 1245 print "you have world", world
1246else 1246else
1247 print "nothing :(" 1247 print "nothing :("
1248``` 1248```
1249<YueDisplay> 1249<YueDisplay>
1250<pre> 1250<pre>
1251if hello = os.getenv "hello" 1251if hello := os.getenv "hello"
1252 print "You have hello", hello 1252 print "You have hello", hello
1253elseif world = os.getenv "world" 1253elseif world := os.getenv "world"
1254 print "you have world", world 1254 print "you have world", world
1255else 1255else
1256 print "nothing :(" 1256 print "nothing :("
@@ -1259,13 +1259,13 @@ else
1259 1259
1260If assignment with multiple return values. Only the first value is getting checked, other values are scoped. 1260If assignment with multiple return values. Only the first value is getting checked, other values are scoped.
1261```moonscript 1261```moonscript
1262if success, result = pcall -> "get result without problems" 1262if success, result := pcall -> "get result without problems"
1263 print result -- variable result is scoped 1263 print result -- variable result is scoped
1264print "OK" 1264print "OK"
1265``` 1265```
1266<YueDisplay> 1266<YueDisplay>
1267<pre> 1267<pre>
1268if success, result = pcall -> "get result without problems" 1268if success, result := pcall -> "get result without problems"
1269 print result -- variable result is scoped 1269 print result -- variable result is scoped
1270print "OK" 1270print "OK"
1271</pre> 1271</pre>
@@ -1374,7 +1374,7 @@ try
1374 func 1, 2, 3 1374 func 1, 2, 3
1375 1375
1376-- working with if assignment pattern 1376-- working with if assignment pattern
1377if success, result = try func 1, 2, 3 1377if success, result := try func 1, 2, 3
1378catch err 1378catch err
1379 print yue.traceback err 1379 print yue.traceback err
1380 print result 1380 print result
@@ -1402,7 +1402,7 @@ try
1402 func 1, 2, 3 1402 func 1, 2, 3
1403 1403
1404-- working with if assignment pattern 1404-- working with if assignment pattern
1405if success, result = try func 1, 2, 3 1405if success, result := try func 1, 2, 3
1406catch err 1406catch err
1407 print yue.traceback err 1407 print yue.traceback err
1408 print result 1408 print result