Hello, Raven
The REPL
On its own, the raven command launches a REPL. It makes a nifty little calculator:
$ raven
> 2+2
4
> Complex(1, 2) / 2
0.5 + 1.0im
> factorial(big(50))
big(30414093201713378043612608166064768844377641568960512000000000000)
Running a script
Like Ruby or Python, there's no main function; code at the top level just runs, line by line. So this one-liner is a complete program:
println("Cacaw, World!")
$ raven hello.rv
Cacaw, World!
Building a binary
Under the hood, raven hello.rv compiles your code to WebAssembly and immediately runs it. You can split those steps up:
$ raven build hello.rv
$ raven hello.wasm
Cacaw, World!
The .wasm file is a self-contained binary that any WebAssembly runtime can execute. You can name the output with -o, so the above is the same as raven build hello.rv -o hello.wasm.
Building for JavaScript
Raven can also emit a JS file, ready for Node or the browser:
$ raven build --js hello.rv
$ ./hello.js
Cacaw, World!
Adding --embed packs the wasm inside the JS, giving you a single self-contained script:
$ raven build --js --embed hello.rv -o hello
$ ./hello
Cacaw, World!
See Embedding Raven in JS/TS for how to call Raven functions from JavaScript, and the CLI reference for all the build options.
Something meatier
Here's a program that actually computes something:
fn fib(n) { fib(n-1) + fib(n-2) }
fn fib(1) { 1 }
fn fib(0) { 0 }
fn fibSequence(n) {
xs = []
for i = range(1, n) {
append(&xs, fib(i))
}
return xs
}
show fibSequence(10)
$ raven fib.rv
fibSequence(10) = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
A few things to notice: fib is defined three times, and calls pick the right definition by matching on the arguments; append(&xs, ...) uses the swap operator to update a variable; and show is a handy macro that prints an expression along with its value.
From here, work through the Language Guide – it starts from the basics and covers everything the language can do today.