Roo

A programming language.

Latest release 2.5.1

What is it?

Roo is an interpreted, object-oriented, dynamically typed scripting language. It’s written in Xojo and it’s designed to be used both from the command line as a productivity tool and also as a replacement for Xojo’s built-in scripting language (XojoScript) in your own Xojo projects. Why replace XojoScript? Well, Roo has a far richer standard library and provides access to very useful built-in classes like hash maps (a.k.a. dictionaries) and regular expressions.

Syntax

Roo’s syntax has some similarities to traditional C-style languages with curly braces acting as block delimiters but mixes in the brevity of scripting languages such as Ruby. Semicolons are optional and whitespace (outside of text) is ignored.

# Operators.
+, -, *, /, %, +=, -=, *=, /=, %=, <, >, <>, !, ^

# Keywords.
and, break, class, else, exit, for, function, if, module, not
or, quit, require, return, self, static, super, var, while

# Numbers.
10
3.5
0.07
1e6
8.6e10

# Strings.
"Strings can be double quoted"
'or single quoted'

# Regex literals are enclosed in pipes.
|\w+\.\w+@\w+\.com| # A comment.
"cool".match(|\w.*|se)

# Hashes.
var ages = {"Bob" => 30, "Liz" => 10}
print(ages.has_key?("Bob")) # => True
print(ages.has_key?("bob")) # => False

# Dates.
var now = DateTime()
print(now.add_days(1).tomorrow?) # => True

# The classic fibonacci function.
function fibonacci(n) {
    if (n < 2) return n
    return fibonacci(n - 1) + fibonacci(n - 2)
}

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

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

Start learning Roo by reading the documentation.

Objects

Inspired by Ruby, absolutely everything in Roo is an object. Even text and number literals:

9.sqrt # => 3
"hello world".capitalise # => "HELLO WORLD"
"t.stark@stark.com".match(|\w+\.\w+@\w+\.com|) # => True

Learn more about Roo’s object system.

Full class system

As an object-oriented language, Roo supports classes with single inheritance. It also supports modules and static methods. Classes can have fields added to them dynamically at any time.

class Person {
    init(name) {
        self.name = name
    }

    greet(who) {
        print("Hello " + who)
    }
}

class Doctor < Person {
    init(name) {
        super.init(name)
    }

    diagnose(who) {
        print("OK " + who + ", let's see what's wrong with you")
    }
}

var dave = Person("Dave");
dave.greet("Tony") # => "Hello Tony"

var garry = Doctor("Garry")
garry.diagnose("Steven") # => "OK Steven, let's see what's wrong with you"

Learn more about Roo’s classes.

Easy to integrate with Xojo

I love Xojo and create all the time with it. I found that I often wanted to offer the ability to my users to extend the functionality of my apps. Xojo provides XojoScript for this purpose but it’s underpowered, particularly the inability to pass objects between a script and its context. Roo is easy to integrate into Xojo apps to provide your end users with more power to write plugins and other extensions. All you need to do is drop in the Roo module and you’re good to go.

Learn how to integrate Roo into a Xojo project.