Start hacking on "if" expressions.

This commit is contained in:
Bob Nystrom
2013-11-05 15:40:21 -08:00
parent 67356df1f9
commit 3db228eecf
6 changed files with 303 additions and 8 deletions
+31
View File
@@ -0,0 +1,31 @@
// Single line.
{ io.write("ok") }.call // expect: ok
// No trailing newline.
{
io.write("ok") }.call // expect: ok
// Trailing newline.
{
io.write("ok") // expect: ok
}.call
// Multiple expressions.
{
io.write("1") // expect: 1
io.write("2") // expect: 2
}.call
// Extra newlines.
{
io.write("1") // expect: 1
io.write("2") // expect: 2
}.call
// TODO(bob): Arguments.
+16
View File
@@ -0,0 +1,16 @@
// Evaluate the 'then' expression if the condition is true.
if (true) io.write("good") // expect: good
if (false) io.write("bad")
// Evaluate the 'else' expression if the condition is false.
if (true) io.write("good") else io.write("bad") // expect: good
if (false) io.write("bad") else io.write("good") // expect: good
// Return the 'then' expression if the condition is true.
io.write(if (true) "good") // expect: good
// Return null if the condition is false and there is no else.
io.write(if (false) "bad") // expect: null
// Return the 'else' expression if the condition is false.
io.write(if (false) "bad" else "good") // expect: good