Contents

Roo

Fibonacci Numbers

A little more challenging than the “Hello World!” script is the following example which prints out the first 15 numbers in the Fibonacci sequence. It also keeps track of how long it takes and prints that out too:

function fibonacci(n) {
    if n < 2 return n
    return fibonacci(n - 1) + fibonacci(n - 2)
}

var start = Roo.clock

print("Here are the first 15 fibonacci numbers:");
for (var i = 0; i < 15; i = i + 1) {
    print(fibonacci(i))
}

print("Time: " + (Roo.clock - start) + " microseconds.")

You should see an output something like this:

Here are the first 15 fibonacci numbers:
0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
Time: 127164.7 microseconds.

The above code will make more sense as you continue to read the documentation but we can already pick out some features of the Roo language.

  • You can define your own functions without the need to specify the return type
  • All objects have a Text representation and can be concatenated with the + operator
  • Roo supports recursion
  • Modules (e.g: the Roo module) exist and provide a powerful way to namespace code