Getting Started
RocketLang started as a complete implementation of MonkeyLang — the language built in Writing an Interpreter in Go — and has been extended since with features both useful and not so useful.
Latest Version
Quick Start
// Values carry methods.
name = "rocket-lang"
print(name.uppercase()) // ROCKET-LANG
print(name.split("-").size()) // 2
// Arrays and hashes, both with methods of their own.
crew = ["ada", "grace", "alan"]
print(crew.size()) // 3
print(crew.contains?("ada")) // true
ages = {"ada": 36, "grace": 45}
print(ages["grace"]) // 45
// Functions are values, so they can be passed around.
double = def(n)
return n * 2
end
print(double(21)) // 42
// Blocks close with `end`, and parentheses around a condition are optional.
foreach i, member in crew
if i > 0
print(i.to_string() + ": " + member)
end
end
// Errors are values you can catch.
begin
print(1 / 0)
rescue e
print("caught: " + e.message())
end
Split a program across files with modules, and pull in someone else's with planets:
import "./helpers" as helpers
For longer programs, the examples directory has solutions to several Advent of Code puzzles.
Help
Launch RocketLang with -h or --help for an overview of the CLI.
$ rocket-lang -h
Usage: rocket-lang [flags] [program file] [arguments]
rocket-lang planet <command>
Available flags:
-e, --exec string Runs the given code.
-v, --version Prints the version and build date.
Run a file, evaluate a snippet, or start a REPL with no arguments at all:
$ rocket-lang program.rl
$ rocket-lang -e 'print("hi")'
$ rocket-lang