v. vanilla 2.0
THE VANILLA HANDBOOK / 2.0

Write useful scripts

Learn the language by building small, readable programs.

Variables and literal text

Declare names without $; reference them with $. Variables are local to each function call. Quotes group a literal token; they do not interpolate variables.

var name
set $name Ada
print "Hello, " $name "\n"
print "$name is literal text\n"

Comments begin with # at a token boundary. Use double quotes for text with spaces. Single quotes do not group strings.

Functions and return values

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

Named parameters also retain legacy positional access: %1 is the first argument. Exact arity is checked. return concatenates scalar text; returnvalue preserves a typed JSON value or native array.

Loops and comparisons

function main 0
    var i total
    set $total 0
    for $i 1 6
        math $total $total + $i
    end for
    if $total == 15
        print "Sum: " $total "\n"
    else
        print "Unexpected result\n"
    end if
kill main

The end of a for range is exclusive. Comparisons use == != < > <= >=; they are not general expressions. Calculate first, then compare. break exits the nearest loop; continue advances it.

JSON is explicitly typed

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

Use json stringify for structured output and json text for a primitive. Legacy string arrays and JSON arrays are different types. Ordinary map set text becomes a JSON string; parse a Boolean/number first when you want its type preserved.

Recover from ordinary errors

function main 0
    var result error
    try
        math $result 1 / 0
    catch $error
        print "Calculation could not be completed\n"
    end try
kill main

Resource-limit failures are fatal and cannot be caught to reset budgets. Catching an error does not undo earlier output, file writes or network operations.

Organize a growing project

Put reusable functions in a .v file and load it with include helpers.v at the top level. Includes resolve relative to the including source file; runtime file operations resolve relative to the process working directory. Avoid globals: pass values into functions and return results explicitly.

Continue with JSON, files & HTTP, SQLite, CSV & dates, or the complete language reference.