Home / Guides

Guides

From a clone to something that runs, in five steps.

Read the docs Source

Getting started

  1. Build it

    Clone, then compile the CLI. Use -cc gcc: the default C backend fails on this checkout, and CI uses the same flag so the two cannot disagree.

    git clone https://github.com/metif12/vlip
    cd vlip
    
    v -cc gcc -o vlip.exe vlip.v
    .\vlip.exe examples\01_basics.lip
  2. Define something

    A lambda takes a parameter list and a body. Define binds it. map applies it to each element.

    (define (square n) (* n n))
    
    (map square [1 2 3 4])   ;=> (1 4 9 16)
  3. Branch on values

    cond takes clauses in order and runs the body of the first whose test is true. The else clause catches the rest.

    (define (fizzbuzz n)
      (cond [(= 0 (mod n 15)) "FizzBuzz"]
            [(= 0 (mod n 3))  "Fizz"]
            [(= 0 (mod n 5))  "Buzz"]
            [else n]))
    
    (map fizzbuzz (range 1 16))
  4. Write a loop that is not a loop

    An ordinary recursive function whose call is in tail position. The continuation stack does not grow, so depth is limited by memory rather than by the stack.

    (define (fold-left f init xs)
      (if (null? xs)
          init
          (fold-left f (f init (car xs)) (cdr xs))))
    
    (fold-left + 0 [1 2 3 4 5])   ;=> 15
  5. Or use loop

    loop is a named let: it advances the variable for you. Same constant space, less to get wrong.

    ; a sum loop needs no stack at all
    (define (sum-to n)
      (loop i 0 (<= i n)
        (set! n (- n i))))
    
    (sum-to 1000000)   ; runs in constant space

Where to go next

The examples directory is the best next stop. Six programs, and they are the specification the interpreter is written against: if the interpreter and an example disagree, one of them is wrong and the example usually wins.

After that, the roadmap. It names what is broken, what is next, and which order those things have to happen in.

Contributing

Bug reports and pull requests are welcome, including translations. The contributing guide covers how to build, how to run the tests, and the branch layout.