Builtin functions

Some functions are builtin like println. Here is the complete list:

Try it...

[!NOTE] Although the print functions take a string, V accepts other printable types too. See below for details.

There is also a special built-in function called dump.

println

println is a simple yet powerful builtin function, that can print anything: strings, numbers, arrays, maps, structs.

Try it...

See also String interpolation.

Printing custom types

If you want to define a custom print value for your type, simply define a str() string method:

Try it...

Dumping expressions at runtime

You can dump/trace the value of any V expression using dump(expr). For example, save this code sample as factorial.v, then run it with v run factorial.v:

Try it...

You will get:

[factorial.v:2] n <= 1: false
[factorial.v:2] n <= 1: false
[factorial.v:2] n <= 1: false
[factorial.v:2] n <= 1: false
[factorial.v:2] n <= 1: true
[factorial.v:3] 1: 1
[factorial.v:5] n * factorial(n - 1): 2
[factorial.v:5] n * factorial(n - 1): 6
[factorial.v:5] n * factorial(n - 1): 24
[factorial.v:5] n * factorial(n - 1): 120
120

Note that dump(expr) will trace both the source location, the expression itself, and the expression value.