-
-
Notifications
You must be signed in to change notification settings - Fork 159
/
Copy pathsample.nrs
37 lines (31 loc) · 946 Bytes
/
sample.nrs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Run this example with `cargo run --example nano_rust -- examples/sample.nrs`
// Feel free to play around with this sample to see what errors you can generate!
// Spans are propagated to the interpreted AST so you can even invoke runtime
// errors and still have an error message that points to source code emitted!
fn mul(x, y) {
x * y
}
// Calculate the factorial of a number
fn factorial(x) {
// Conditionals are supported!
if x == 0 {
1
} else {
mul(x, factorial(x - 1))
}
}
// The main function
fn main() {
let three = 3;
let meaning_of_life = three * 14 + 1;
print("Hello, world!");
print("The meaning of life is...");
if meaning_of_life == 42 {
print(meaning_of_life);
} else {
print("...something we cannot know");
print("However, I can tell you that the factorial of 10 is...");
// Function calling
print(factorial(10));
}
}