首页 / 指南
指南
五步之内,从一份克隆到能跑起来的东西。
本节尚未翻译成你的语言,暂时以英文显示。欢迎提交翻译。
开始使用
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.lipDefine 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)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))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]) ;=> 15Or 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
本节尚未翻译成你的语言,暂时以英文显示。欢迎提交翻译。
接下来去哪
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.
本节尚未翻译成你的语言,暂时以英文显示。欢迎提交翻译。
参与贡献
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.