diff --git a/language/samples/closure.cul b/language/samples/closure.cul new file mode 100644 index 0000000..5c04355 --- /dev/null +++ b/language/samples/closure.cul @@ -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() }") diff --git a/language/samples/fib.cul b/language/samples/fib.cul new file mode 100644 index 0000000..b1913c2 --- /dev/null +++ b/language/samples/fib.cul @@ -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 +} diff --git a/language/samples/fizzbuzz.cul b/language/samples/fizzbuzz.cul new file mode 100644 index 0000000..87e5810 --- /dev/null +++ b/language/samples/fizzbuzz.cul @@ -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 +}