V
2019fragletsystemsimperativeconcurrent.v
docker run --rm --platform="linux/amd64" 100hellos/vlang:latest
MCP + fragletc
MCPstdinargs
This language supports code execution via MCP and the fragletc CLI. Stdin piping and argument passing are both supported.
Install fragletc →V is a systems imperative and concurrent language first appearing in 2019.
Hello World
#!/usr/bin/env sh
cd /hello-world
# This uses the vlang REPL to build the program
chmod +x hello-world.v
# This transpiles the vlang program to C and also compiles it
# This is the slickest transpilation + compilation combo I've seen so far
./hello-world.v
./hello-world "$@"Coding Guide
Language Version
V (latest from Alpine edge repositories)
Execution Model
- Compiled language
- Code is compiled to a binary, then executed
- Standard V execution model with
main()function
Key Characteristics
- Statically typed with type inference
- Case-sensitive
- Garbage collected
- Similar syntax to Go but with some differences
- No null values (uses Option types)
- Immutable by default (use
mutfor mutable variables) - Functions are first-class citizens
- Module-based organization
- Built-in concurrency support
- Fast compilation
Fragment Authoring
Write valid V code. Your fragment can define functions, types, and the main() function. Your fragment will be compiled and executed.
Available Libraries
The standard library includes:
println()- Print with newlineprint()- Print without newlineeprintln()- Print to stderr with newline
Additional standard library modules can be imported as needed:
os- Operating system interfacestrings- String manipulationmath- Mathematical functionstime- Time operationsjson- JSON encoding/decodinghttp- HTTP client and server- And many more from the V standard library
Common Patterns
- Print:
println('message')orprintln('format ${value}') - Variables:
x := 10(type inference) orx int = 10(explicit type) - Mutable variables:
mut x := 10thenx = 20 - Functions:
fn add(a int, b int) int { return a + b } - Structs:
struct Person { name string age int } - Methods:
fn (p Person) greet() { println('Hello, ${p.name}') } - Arrays:
numbers := [1, 2, 3]ornumbers := []int{cap: 10} - Maps:
m := map[string]int{}orm := {'a': 1, 'b': 2} - String interpolation:
'Hello, ${name}!' - Option types:
x ?int(can benoneorsome(value)) - Error handling:
result := fn_that_may_fail() or { return }
Examples
// Simple output
fn main() {
println('Hello from fragment!')
}
// Variables and calculations
fn main() {
a := 5
b := 10
println('Sum: ${a + b}')
}
// Functions
fn add(a int, b int) int {
return a + b
}
fn main() {
result := add(5, 10)
println('5 + 10 = ${result}')
}
// Arrays and loops
fn main() {
numbers := [1, 2, 3, 4, 5]
mut sum := 0
for num in numbers {
sum += num
}
println('Sum: ${sum}')
}
// Structs and methods
struct Person {
name string
age int
}
fn (p Person) greet() {
println('${p.name} is ${p.age} years old')
}
fn main() {
p := Person{name: 'Alice', age: 30}
p.greet()
}
// Maps
fn main() {
mut m := map[string]int{}
m['apple'] = 5
m['banana'] = 3
println('Apples: ${m['apple']}')
}
// String operations
fn main() {
mut s := 'Hello'
s += ' World!'
println(s)
println('Length: ${s.len}')
}
// Mutable variables
fn main() {
mut x := 10
x = 20
println('x = ${x}')
}Caveats
- Fragments must be valid V code that compiles
- Variables are immutable by default - use
mutkeyword for mutable variables - V has no null values - use Option types (
?int,?string, etc.) instead - String interpolation uses
${expression}syntax - Arrays are zero-indexed
- The code is compiled fresh each time, so compilation errors will fail execution
- Type inference is powerful but explicit types can be clearer
- Functions must have explicit return types
- Struct fields are private by default (lowercase) - use uppercase for public fields
- V is still evolving, so some features may change
Fraglet Scripts
Echo Args
#!/usr/bin/env -S fragletc --vein=vlang
import os
fn main() {
println('Args: ' + os.args[1..].join(' '))
}Stdin Upper
#!/usr/bin/env -S fragletc --vein=vlang
import os
fn main() {
line := os.input('')
println(line.to_upper())
}Test
#!/usr/bin/env -S fragletc --vein=vlang
fn main() {
println('Hello World!')
}Vlang Fortune
#!/usr/bin/env -S fragletc --vein=vlang
// One from the vault: V fortunes
fn main() {
println('V: 400KB compiler. 2 second boot. Your move, Rust.')
}Connections
influenced by