Many programmers find it tedious to learn a language's syntax from a formal grammar. This web page provides a quick reference to Vault's syntax by providing a single example of every major construct in the language. Since Vault statements and expressions are familiar from C, the code below has few examples of these. (Hovering the mouse over a syntactic element will provide information about that element.) For a more complete reference, we also have a formal grammar.
extern module Region : extern REGION;
interface SampleIntf { type color; type stack<$T>; type length = int; length size<$T>(stack<$T>); float const pi; struct point { int x,y; }; point? cursor; } module SampleMod : SampleIntf { type color = (int,int,int); variant stack<$T> [ `Empty | `Node($T,stack<$T>) ]; type length = int; length size<$T>(stack<$T> stk) { switch (stk) { case `Empty: return 0; case `Node(_,stk2): return 1 + size(stk2); } } float const pi = 3.14159; module Inner { int const ZERO = 0; } struct point { int x,y; }; point? cursor = new point {x=Inner.ZERO; y=Inner.ZERO;}; int privatefun<$L:key>(tracked($R) region rgn, {$R}:int[$L] array, tracked($L) int len) [-$R] { int average($Q:int[$L] arr) [$Q] { int sum = 0; for (int i=0; i<arr.length; i++) sum += arr[i]; return sum / arr.length; } int avg = average(array); Region.delete(rgn); return avg; } }