← Back to Demos & Examples

01_basics_and_math.vk

Raw .vk
// Example 01: Core syntax, rich literals, spaced infix math, bitwise ops, ranges, and loops
// Track A (ORO VM) : veko run examples/01_basics_and_math.vk
// Track A (.vko)   : veko compile --vko examples/01_basics_and_math.vk -o dist/01.vko ; veko run dist/01.vko
// Track B (Wasm 3) : veko run --wasm examples/01_basics_and_math.vk
// Track C (Native) : veko compile --native examples/01_basics_and_math.vk -o dist/01.exe ; ./dist/01.exe

title = 'Veko Basics'
timeout = 250ms
buf-cap = 4kb
proto = .tcp

println title
println timeout
println buf-cap
println proto

// Spaced infix arithmetic & bitwise ring-buffer indexing
head = 12
offset = 7
cap = 16
next-slot = (head + offset) & (cap - 1)
println next-slot

// Ranges & tight slicing
nums = 1..=5
println (mold nums)
println (mold nums[1..4])

// Control flow: if, unless, while
mut i = 0
mut sum = 0
while i < 5 [
	i = i + 1
	sum = sum + i
]
println sum

unless zero? sum [
	println 'sum-nonzero'
]