v. vanilla 2.0
THE VANILLA HANDBOOK / 2.0

Example library

Copy, download and run small complete programs.

Real scripts, not a simulated playground

These small examples are executed against the native release and sanitizer binaries when this site is verified. Download a .v file or copy its source, then run it locally.

Hello, World!

Download hello.v

function main 0
    var name
    set $name "World"
    print "Hello, " $name "!\n"
kill main
./build/vanilla1  run hello.v

Expected output:

Hello, World!

Functions

Download functions.v

function double value
    var result
    math $result $value * 2
    return $result
kill double
function main 0
    var result
    call $result double 21
    print $result "\n"
kill main
./build/vanilla1  run functions.v

Expected output:

42

Loops

Download loop.v

function main 0
    var i total
    set $total 0
    for $i 1 6
        math $total $total + $i
    end for
    print "Sum: " $total "\n"
kill main
./build/vanilla1  run loop.v

Expected output:

Sum: 15

Typed JSON

Download json.v

function main 0
    var data value text
    json parse $data "{\"language\":\"Vanilla\",\"version\":2}"
    json get $value $data language
    json text $text $value
    print $text "\n"
kill main
./build/vanilla1  run json.v

Expected output:

Vanilla

Prepared SQLite query

Download sqlite.v

function main 0
    var h params rows text
    db open $h ":memory:"
    json parse $params "[42]"
    db query $rows $h "SELECT ? AS answer" $params
    json stringify $text $rows
    print $text "\n"
    db close $h
kill main
./build/vanilla1 --allow-db run sqlite.v

Expected output:

[{"answer":42}]