
vv programming language
This project is still in early stage of development. Nothing useful for end-users.
Features
- simple and enough, friendly syntax
- bool, number, string (with interpolation), list and record
- function, if-else-end, while, defer and variables
- modular system with
import and pub
How it looks
import console from 'std/console.vv'
// let's define very simple function
fun add(a, b)
return a + b
end
// define variable
let x = 0
// function is a value
let incr_x = fun ()
// variables are mutable
x += 1
end
// we have if-end and if-else-end
if x < 10
console.print('x is less than 10.')
end
// we have while, break and continue too
// but, we don't have for or for-in
let i = 0
while i < 10
// call some functions
incr_x()
i += 1
end
let name = "world"
console.print("Hello, {name}!")
console.print(x) // 11
For more information about the language and tooling, see Documentation.
Embedding
You can embed vvlang into your Go projects.
package main
import (
"fmt"
"github.com/fj68/vvlang/interp"
"github.com/fj68/vvlang/lib"
"github.com/fj68/vvlang/mod"
)
func main() {
cfg := mod.DefaultConfig()
// 1. Create a new state via builder
s := interp.NewStateBuilder(cfg, "main.vv").
// 2. Register standard library
WithBuiltinModules(lib.Std.Natives).
// 3. Register your own native function
WithNative("hello", interp.VBuiltinFun(func(s *interp.State, args []interp.Value) (interp.Value, error) {
fmt.Println("Hello from Go!")
return interp.NoneValue, nil
})).
// 4. Build the state
Build()
s.EnsureSystemLibrary(lib.Std.Name, lib.Std.FS)
// 5. Evaluate code
code := `
import console from 'std/console.vv'
extern "native" fun hello()
hello()
`
s.Eval([]rune(code))
}
Development
Assuming latest golang is installed:
# clone the repo
git clone git@github.com:fj68/vvlang.git
cd vvlang
# install dependent modules
go mod tidy
# build executable
go build -o vv
# run interpreter
vv ./test.vv