Examples

Here you will find some example krill programs.

Date and time

(map toNumber . split "-" . date) ()
# => [2019,5,11]

(map toNumber . split ":" . time) ()
# => [17,40]

File I/O

writeFile "/var/tmp/foo" "hello world"

readFile "/var/tmp/foo"
# => "hello world"

appendFile "/var/tmp/foo" "\nhow are you?"

readFile "/var/tmp/foo"
# => hello world
# => how are you?

Factorial

fac = n -> {
  if n == 0 then 1
  else n * (fac $ n - 1)
}

Fibonacci

fib = n -> {
  if n == 0 then 0
  else {
   if n == 1 then 1
   else fib (n - 1) + fib (n - 2)
  }
}

FizzBuzz

div3 = i -> i % 3 == 0
div5 = i -> i % 5 == 0
div35 = i -> (div3 i) && (div5 i)

for i in [1..100] {
  if div35 i then print "FizzBuzz"
  else {
    if div3 i then print "Fizz"
    else {
      if div5 i then print "Buzz"
      else print i
    }
  }
}