-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
print("x should be 78:"); | ||
// This script contains a single assignment statement. | ||
|
||
let x = 78; | ||
|
||
print(x); | ||
print(`x should be 78: ${x}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
// This script defines a function and calls it | ||
// This script defines a function and calls it. | ||
|
||
fn bob() { | ||
fn call_me() { | ||
return 3; | ||
} | ||
|
||
let result = bob(); | ||
let result = call_me(); | ||
|
||
print(`bob() should be 3: ${result}`); | ||
print(`call_me() should be 3: ${result}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
// This script defines a function with two parameters | ||
// This script defines a function with two parameters and local variables. | ||
|
||
let a = 3; | ||
|
||
fn addme(a, b) { | ||
fn add(a, b) { | ||
a = 42; // notice that 'a' is passed by value | ||
a + b; // notice that the last value is returned even if terminated by a semicolon | ||
} | ||
|
||
let result = addme(a, 4); | ||
let result = add(a, 4); | ||
|
||
print(`addme(a, 4) should be 46: ${result}`); | ||
print(`add(a, 4) should be 46: ${result}`); | ||
|
||
print(`a should still be 3: ${a}`); // should print 3 - 'a' is never changed | ||
print(`a should still be 3: ${a}`); // prints 3: 'a' is never changed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This script imports an external script as a module. | ||
|
||
import "loop" as x; | ||
|
||
print(`Module test! foo = ${x::foo}`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This script runs a single expression. | ||
|
||
print("The result should be 46:"); | ||
|
||
print(34 + 12); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This script runs a complex expression. | ||
|
||
print("The result should be 182:"); | ||
|
||
let x = 12 + 34 * 5; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This script runs a complex expression. | ||
|
||
print("The result should be 230:"); | ||
|
||
let x = (12 + 34) * 5; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This script tests object maps and strings. | ||
|
||
print("Ready... Go!"); | ||
|
||
let now = timestamp(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
// This script runs a switch statement in a for-loop. | ||
|
||
let arr = [42, 123.456, "hello", true, "hey", 'x', 999, 1, 2, 3, 4]; | ||
|
||
for item in arr { | ||
switch item { | ||
// Match single integer | ||
42 => print("The Answer!"), | ||
// Match single floating-point number | ||
123.456 => print(`Floating point... ${item}`), | ||
// Match single string | ||
"hello" => print(`${item} world!`), | ||
// Match another integer | ||
999 => print(`Got 999: ${item}`), | ||
// Match range with condition | ||
0..100 if item % 2 == 0 => print(`A small even number: ${item}`), | ||
// Match another range | ||
0..100 => print(`A small odd number: ${item}`), | ||
// Default case | ||
_ => print(`Something else: <${item}> is ${type_of(item)}`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// This script runs a while loop | ||
// This script runs a while loop. | ||
|
||
let x = 10; | ||
|
||
|