add lila source example files
This commit is contained in:
parent
86d4f7fffb
commit
374daaff7f
8 changed files with 49 additions and 0 deletions
3
examples/addition.lila
Normal file
3
examples/addition.lila
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn add(a: int, b: int) int {
|
||||
a + b
|
||||
}
|
||||
4
examples/assign.lila
Normal file
4
examples/assign.lila
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
a = 0;
|
||||
set a = 1;
|
||||
}
|
||||
6
examples/block_as_expr.lila
Normal file
6
examples/block_as_expr.lila
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
fn main() {
|
||||
val = {
|
||||
a = 42;
|
||||
a
|
||||
};
|
||||
}
|
||||
3
examples/hello.lila
Normal file
3
examples/hello.lila
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
fn main() {
|
||||
println("Hello there!");
|
||||
}
|
||||
7
examples/if_expr.lila
Normal file
7
examples/if_expr.lila
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fn main() {
|
||||
val = if true {
|
||||
42
|
||||
} else {
|
||||
1337
|
||||
};
|
||||
}
|
||||
9
examples/infinite_calls.lila
Normal file
9
examples/infinite_calls.lila
Normal 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
4
examples/strings.lila
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
destination = "unknown";
|
||||
set destination = "to the moon";
|
||||
}
|
||||
13
examples/syracuse.lila
Normal file
13
examples/syracuse.lila
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue