The V Programming Language

Simple, fast, safe, compiled language for developing maintainable software github.com/vlang/v 9.7k
Install V from source in 0.5 seconds
wget vlang.io/v.c && gcc -o v v.c
Subscribe to development updates

The playground is temporarily offline. It will be back soon.
In the meantime you can install V on your machine in a couple of seconds.
Or use an alternative playground Judge0: https://vlang.ide.judge0.com.

Check out the docs for more examples
fn main() { areas := ['game', 'web', 'tools', 'science', 'systems', 'GUI', 'mobile'] for area in areas { println('Hello, $area developers!') } } fn fib(n int) int { if n <= 1 { return n } return fib(n - 1) + fib(n - 2) } fn main() { for i := 0; i < 10; i++ { println(fib(i)) } } const ( MAX = 15 ) struct Fib { nums []int } fn (fib mut Fib) calc(n int) int { if n <= 1 { return n } if fib.nums[n] != 0 { return fib.nums[n] } fib.nums[n] = fib.calc(n - 1) + fib.calc(n - 2) return fib.nums[n] } fn main() { mut fib := Fib { nums: [0; MAX] } for i := 0; i < MAX; i++ { println(fib.calc(i)) } } import json struct User { name string age int mut: is_registered bool } fn main() { s := '[{ "name":"Frodo", "age":25}, {"name":"Bobby", "age":10}]' users := json.decode( []User, s) or { eprintln('Failed to parse json') return } for user in users { println('$user.name: $user.age') } println('') for i, user in users { println('$i) $user.name') if !user.can_register() { println('Cannot register $user.name, they are too young') continue } users[i].register() // `user` is immutable, we have to modify the array } // Let's encode users again just for fun println('') println(json.encode(users)) } fn (u User) can_register() bool { return u.age >= 16 } fn (u mut User) register() { u.is_registered = true } struct User { id int name string } struct Repo { users []User } fn new_repo() Repo { return Repo { users: [User{1, 'Andrew'}, User {2, 'Bob'}, User {10, 'Charles'}] } } fn (r Repo) find_user_by_id(id int) User? { for user in r.users { if user.id == id { // V automatically wraps this into an option type return user } } return error('User $id not found') } fn main() { repo := new_repo() // Option types must be handled by `or` blocks user := repo.find_user_by_id(10) or { // `or` block must end with `return`, `break`, or `continue` println('not found') return } println(user.id) // ==> '10' println(user.name) // ==> 'Charles' } struct Color { r int g int b int } fn (c Color) str() string { return '{$c.r, $c.g, $c.b}' } fn rgb(r, g, b int) Color { return Color{r: r, g: g, b: b} } const ( NUMBERS = [1, 2, 3] RED = Color{r: 255, g: 0, b: 0} BLUE = rgb(0, 0, 255) ) fn main() { println(NUMBERS) println(RED) println(BLUE) } struct Vec { x int y int } fn (a Vec) str() string { return '{$a.x, $a.y}' } fn (a Vec) + (b Vec) Vec { return Vec { a.x + b.x, a.y + b.y } } fn (a Vec) - (b Vec) Vec { return Vec { a.x - b.x, a.y - b.y } } fn main() { a := Vec{2, 3} b := Vec{4, 5} println(a + b) println(a - b) } struct User { name string age int } fn main() { user1 := User{'Bob', 20} user2 := { user1 | name: 'Peter' } println(user1.name) println(user1.age) println(user2.name) println(user2.age) }
 
Current version: V 0.1.5

 
This is an alpha stage, please report all issues via GitHub. 

For security reasons, imports are temporarily disabled, the size of the program is limited,
and your program can't run for more than 1 second. 


Coming soon: online C to V translator.

Coming not so soon: online C++ to V translator.