3.0k

The V Programming Language

Simple, fast, safe language created for developing Volt, soon available for everyone.

Open source release in June 2019. Early access since April 15.
Install V from source in 0.5 seconds
wget vlang.io/v.c && gcc -o v v.c
Subscribe to development updates

Your code will be formatted automatically

Check out the docs for more examples
fn main() { areas := ['game', 'web', 'tools', 'science', 'systems', 'GUI'] 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 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') } } // 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 } struct Repo { users []User } fn new_repo() Repo { user := User{id:10} return Repo { users: [user] } } 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' } 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) }
 
Thank you for trying out V.

This is an alpha stage. The language is going to become 
a lot more stable by June.

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.