diff --git a/scripts/array.rhai b/scripts/array.rhai index cc6fc642..1c449fd0 100644 --- a/scripts/array.rhai +++ b/scripts/array.rhai @@ -5,5 +5,4 @@ print(x[1]); x[1] = 5; -print("x[1] should be 5:"); -print(x[1]); +print(`x[1] should be 5: ${x[1]}`); diff --git a/scripts/assignment.rhai b/scripts/assignment.rhai index 82ff7d92..93a03c45 100644 --- a/scripts/assignment.rhai +++ b/scripts/assignment.rhai @@ -1,4 +1,5 @@ print("x should be 78:"); let x = 78; + print(x); diff --git a/scripts/comments.rhai b/scripts/comments.rhai index f5d24c93..dd3612fa 100644 --- a/scripts/comments.rhai +++ b/scripts/comments.rhai @@ -8,4 +8,4 @@ let /* I am a spy in a variable declaration! */ x = 5; /* look /* at /* that, /* multi-line */ comments */ can be */ nested */ -/* surrounded by */ x // comments +/* surrounded by */ this_is_not_a_comment = true // comments diff --git a/scripts/function_decl1.rhai b/scripts/function_decl1.rhai index 908bcdec..2e6a8958 100644 --- a/scripts/function_decl1.rhai +++ b/scripts/function_decl1.rhai @@ -4,6 +4,6 @@ fn bob() { return 3; } -print("bob() should be 3:"); +let result = bob(); -print(bob()); +print(`bob() should be 3: ${result}`); diff --git a/scripts/function_decl2.rhai b/scripts/function_decl2.rhai index 0d72743e..ae14c454 100644 --- a/scripts/function_decl2.rhai +++ b/scripts/function_decl2.rhai @@ -7,10 +7,8 @@ fn addme(a, b) { 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 print 3 - 'a' is never changed +print(`a should still be 3: ${a}`); // should print 3 - 'a' is never changed diff --git a/scripts/if1.rhai b/scripts/if1.rhai index cbfe2938..4e264d64 100644 --- a/scripts/if1.rhai +++ b/scripts/if1.rhai @@ -11,4 +11,4 @@ if a > b { print(x); // should print 0 } else { print("Oops! a == b"); -} \ No newline at end of file +} diff --git a/scripts/loop.rhai b/scripts/loop.rhai index 1b514baf..846450f0 100644 --- a/scripts/loop.rhai +++ b/scripts/loop.rhai @@ -10,3 +10,5 @@ loop { if x <= 0 { break; } } + +export x as foo; diff --git a/scripts/mat_mul.rhai b/scripts/mat_mul.rhai index 9fed0d77..65743a37 100644 --- a/scripts/mat_mul.rhai +++ b/scripts/mat_mul.rhai @@ -12,11 +12,11 @@ fn new_mat(x, y) { fn mat_gen(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 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); } } diff --git a/scripts/module.rhai b/scripts/module.rhai index 77ad12ac..f92fb162 100644 --- a/scripts/module.rhai +++ b/scripts/module.rhai @@ -1,3 +1,3 @@ -import "loop"; +import "loop" as x; -print("Module test!"); +print(`Module test! foo = ${x::foo}`); diff --git a/scripts/op2.rhai b/scripts/op2.rhai index e00a1b99..471e8ee4 100644 --- a/scripts/op2.rhai +++ b/scripts/op2.rhai @@ -1,4 +1,5 @@ print("The result should be 182:"); let x = 12 + 34 * 5; + print(x); diff --git a/scripts/op3.rhai b/scripts/op3.rhai index aa7349a8..73cec23b 100644 --- a/scripts/op3.rhai +++ b/scripts/op3.rhai @@ -1,4 +1,5 @@ print("The result should be 230:"); let x = (12 + 34) * 5; + print(x); diff --git a/scripts/primes.rhai b/scripts/primes.rhai index f5b65763..380750d7 100644 --- a/scripts/primes.rhai +++ b/scripts/primes.rhai @@ -30,4 +30,4 @@ print(`Run time = ${now.elapsed} seconds.`); if total_primes_found != 78_498 { print("The answer is WRONG! Should be 78,498!"); -} \ No newline at end of file +} diff --git a/scripts/string.rhai b/scripts/string.rhai index a507648c..21ea022b 100644 --- a/scripts/string.rhai +++ b/scripts/string.rhai @@ -34,4 +34,13 @@ made using multi-line literal 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 <<<");