Added samples for Culebra toy language.

This commit is contained in:
yhirose 2015-06-12 14:17:53 -04:00
parent 341659f699
commit d93682dc56
3 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,17 @@
/*
* Closure test
*/
make_func = fn (mut x) {
mut n = 100
fn () {
n = n + 1
x = x + 1 + n
}
}
f = make_func(10)
pp("1: { f() }")
pp("2: { f() }")
pp("3: { f() }")

17
language/samples/fib.cul Normal file
View File

@ -0,0 +1,17 @@
/*
* Fibonacci
*/
fib = fn (x) {
if x < 2 {
x
} else {
self(x - 2) + self(x -1)
}
}
mut i = 0
while i < 30 {
pp("{i}: {fib(i)}")
i = i + 1
}

View File

@ -0,0 +1,17 @@
/*
* Fizz Buzz
*/
mut i = 1
while i < 24 {
if i % 15 == 0 {
pp('FizzBuzz')
} else if i % 5 == 0 {
pp('Buzz')
} else if i % 3 == 0 {
pp('Fizz')
} else {
pp(i)
}
i = i + 1
}