Refine example scripts.

This commit is contained in:
Stephen Chung 2021-04-09 22:48:47 +08:00
parent 0f2e7e3825
commit 2b1555cff8
13 changed files with 27 additions and 16 deletions

View File

@ -5,5 +5,4 @@ print(x[1]);
x[1] = 5; x[1] = 5;
print("x[1] should be 5:"); print(`x[1] should be 5: ${x[1]}`);
print(x[1]);

View File

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

View File

@ -8,4 +8,4 @@ let /* I am a spy in a variable declaration! */ x = 5;
/* look /* at /* that, /* multi-line */ comments */ can be */ nested */ /* look /* at /* that, /* multi-line */ comments */ can be */ nested */
/* surrounded by */ x // comments /* surrounded by */ this_is_not_a_comment = true // comments

View File

@ -4,6 +4,6 @@ fn bob() {
return 3; return 3;
} }
print("bob() should be 3:"); let result = bob();
print(bob()); print(`bob() should be 3: ${result}`);

View File

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

View File

@ -11,4 +11,4 @@ if a > b {
print(x); // should print 0 print(x); // should print 0
} else { } else {
print("Oops! a == b"); print("Oops! a == b");
} }

View File

@ -10,3 +10,5 @@ loop {
if x <= 0 { break; } if x <= 0 { break; }
} }
export x as foo;

View File

@ -12,11 +12,11 @@ fn new_mat(x, y) {
fn mat_gen(n) { fn mat_gen(n) {
let m = new_mat(n, n); let m = new_mat(n, n);
let tmp = 1.0 / n.to_float() / n.to_float(); let tmp = 1.0 / n / n;
for i in range(0, n) { for i in range(0, n) {
for j in range(0, n) { for j in range(0, n) {
m[i][j] = tmp * (i.to_float() - j.to_float()) * (i.to_float() + j.to_float()); m[i][j] = tmp * (i - j) * (i + j);
} }
} }

View File

@ -1,3 +1,3 @@
import "loop"; import "loop" as x;
print("Module test!"); print(`Module test! foo = ${x::foo}`);

View File

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

View File

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

View File

@ -30,4 +30,4 @@ print(`Run time = ${now.elapsed} seconds.`);
if total_primes_found != 78_498 { if total_primes_found != 78_498 {
print("The answer is WRONG! Should be 78,498!"); print("The answer is WRONG! Should be 78,498!");
} }

View File

@ -34,4 +34,13 @@ made using multi-line literal
print(s); print(s);
// Interpolation
let s = `This is interpolation ${
let x = `within ${let y = "yet another level \
of interpolation!"; y} interpolation`;
x
} within literal string.`;
print(s);
print(">>> END <<<"); print(">>> END <<<");