Pretty up scripts with print.

This commit is contained in:
Stephen Chung 2020-05-02 16:23:36 +08:00
parent fc99b981a1
commit fc66a7ecef
11 changed files with 32 additions and 13 deletions

View File

@ -1,7 +1,9 @@
let x = [1, 2, 3];
print(x[1]); // prints 2
print("x[1] should be 2:");
print(x[1]);
x[1] = 5;
print(x[1]); // prints 5
print("x[1] should be 5:");
print(x[1]);

View File

@ -1,2 +1,4 @@
print("x should be 78:");
let x = 78;
print(x);

View File

@ -3,7 +3,8 @@
let /* I am a spy in a variable declaration! */ x = 5;
/* I am a simple
multi-line comment */
multi-line
comment */
/* look /* at /* that, /* multi-line */ comments */ can be */ nested */

View File

@ -4,4 +4,6 @@ fn bob() {
return 3;
}
print(bob()); // should print 3
print("bob() should be 3:");
print(bob());

View File

@ -7,6 +7,10 @@ fn addme(a, b) {
a + b; // notice that the last value is returned even if terminated by a semicolon
}
print(addme(a, 4)); // should print 46
print("addme(a, 4) should be 46:");
print(addme(a, 4));
print("a should still be 3:");
print(a); // should print 3 - 'a' is never changed

View File

@ -4,4 +4,6 @@ fn f(a, b, c, d, e, f) {
a - b * c - d * e - f
}
print(f(100, 5, 2, 9, 6, 32)); // should print 4
print("f() call should be 4:");
print(f(100, 5, 2, 9, 6, 32));

View File

@ -3,12 +3,12 @@ let b = 123;
let x = 999;
if a > b {
print("a > b");
print("Oops! a > b");
} else if a < b {
print("a < b");
print("a < b, x should be 0");
let x = 0; // this 'x' shadows the global 'x'
print(x); // should print 0
} else {
print("a == b");
print("Oops! a == b");
}

View File

@ -1 +1,3 @@
print(34 + 12); // should be 46
print("The result should be 46:");
print(34 + 12);

View File

@ -1,2 +1,4 @@
print("The result should be 182:");
let x = 12 + 34 * 5;
print(x); // should be 182
print(x);

View File

@ -1,2 +1,4 @@
print("The result should be 230:");
let x = (12 + 34) * 5;
print(x); // should be 230
print(x);