Fibonacci


No standard library would be complete without an obligatory definition of the Fibonacci function. Using all of the above things we’ve defined we can write a cute little fib function that is really quite readable, and clear semantically.

  1. ; Fibonacci
  2. (fun {fib n} {
  3. select
  4. { (== n 0) 0 }
  5. { (== n 1) 1 }
  6. { otherwise (+ (fib (- n 1)) (fib (- n 2))) }
  7. })

This is the end of the standard library I’ve written. Building up a standard library is a fun part of language design, because you get to be creative and opinionated on what goes in and stays out. Try to come up with something you are happy with. Exploring what is possible to define and do can be very interesting.