add lila source example files

This commit is contained in:
Romain Paquet 2023-10-16 22:36:33 +02:00
parent 86d4f7fffb
commit 374daaff7f
8 changed files with 49 additions and 0 deletions

3
examples/addition.lila Normal file
View file

@ -0,0 +1,3 @@
fn add(a: int, b: int) int {
a + b
}

4
examples/assign.lila Normal file
View file

@ -0,0 +1,4 @@
fn main() {
a = 0;
set a = 1;
}

View file

@ -0,0 +1,6 @@
fn main() {
val = {
a = 42;
a
};
}

3
examples/hello.lila Normal file
View file

@ -0,0 +1,3 @@
fn main() {
println("Hello there!");
}

7
examples/if_expr.lila Normal file
View file

@ -0,0 +1,7 @@
fn main() {
val = if true {
42
} else {
1337
};
}

View file

@ -0,0 +1,9 @@
fn foo(a: int) int {
b = baz(a);
b
}
fn baz(b: int) int {
a = foo(b);
a
}

4
examples/strings.lila Normal file
View file

@ -0,0 +1,4 @@
fn main() {
destination = "unknown";
set destination = "to the moon";
}

13
examples/syracuse.lila Normal file
View file

@ -0,0 +1,13 @@
// Computes the syracuse sequence with the given inital term
// until it reaches 1 (it probably will).
fn syracuse(x0: int) int {
x = x0;
while x != 1 {
if x % 2 == 0 {
set x = x / 2;
} else {
set x = 3 * x + 1;
};
};
x
}