Examples

Every snippet below is real Vect that runs on vectc. Run with vectc file.vt.

1 · Variables & math
vectfn main
    a10
    b20
    (c.a+b)              cmt c = 30
    echo "Sum:"
    echo c
    val16
    (root.sqrt.val)      cmt root = 4
    echo root
    (shlRes.bit shl a, 2)   cmt 10 << 2 = 40
    echo shlRes
    (shrRes.bit shr b, 1)   cmt 20 >> 1 = 10
    echo shrRes
main()
2 · Branching & loops
vectfn main
    x15
    if x > 10
        echo "x is greater than 10"
    els
        echo "x is 10 or less"
    counter0
    lo10
        echo counter
        (counter.counter+1)
    running1
    val0
    lo10w running == 1
        echo val
        (val.val+1)
        if val == 3
            running0
main()
3 · Functions
vectfn add.a, b
    (sum.a+b)
    rtn sum
vectfn main
    (result.add 25, 75)
    echo "Function Result (25 + 75):"
    echo result
main()
4 · Arrays
vectfn main
    arr(5)
    set arr, 0, 10
    set arr, 1, 20
    set arr, 2, 99
    (x.get arr, 2)
    echo "Value at index 2:"
    echo x
main()
5 · Files
vectfn main
    fopen fh, "notes.txt", "w"
    fwrite fh, "hello vect"
    fclose fh
    fopen fr, "notes.txt", "r"
    (s.fread fr, 64)
    fclose fr
    echo s
main()
6 · Input & live refresh
vectfn main
    vga0x320200
    echo "Press any key to test input..."
    timer0
    lo1000w true
        in(key)
        if key > 0
            echo "Key pressed ASCII code:"
            echo key
        (timer.timer+1)
        echow timer, 100
main()
7 · Header library (.vth)
cmt mylib.vth — reusable functions
vectfn double.x
    (d.x*2)
    rtn d
cmt use it: name the file in the header
vt.init
mylib.vth
(main)
branch
vectfn main
    (r.double 21)
    echo r          cmt 42
main()
8 · Floats
vectfn main
    y3.14
    (r.y*2)          cmt 6.28
    echo r
    a10
    (m.a+y)          cmt 13.14, int promotes to float
    echo m
main()
9 · Strings
vectfn main
    msg"hello"
    (n.len msg)              cmt 5
    echo n
    (c.char msg, 1)          cmt 101 ('e')
    echo c
    (greet.cat msg, " you")  cmt "hello you"
    echo greet
    if msg == msg
        echo "same"
main()