Lisvy
A LISP interpreter written in Rust 🦀
About
Lisvy is a playful blend of LISP, Rust, and Vibe — as in vibe coding. The name itself was suggested by AI, fitting for a project that was built through collaborative AI-assisted development.
Installation
Download the latest binary from the Releases page.
macOS
# Download (Apple Silicon)
curl -L https://github.com/leocavalcante/lisvy/releases/latest/download/lisvy-macos-aarch64 -o lisvy
# Or Intel Mac
curl -L https://github.com/leocavalcante/lisvy/releases/latest/download/lisvy-macos-x86_64 -o lisvy
# Make executable and remove quarantine
chmod +x lisvy
xattr -d com.apple.quarantine lisvy
# Move to PATH
sudo mv lisvy /usr/local/bin/
Linux
curl -L https://github.com/leocavalcante/lisvy/releases/latest/download/lisvy-linux-x86_64 -o lisvy
chmod +x lisvy
sudo mv lisvy /usr/local/bin/
Build from Source
git clone https://github.com/leocavalcante/lisvy.git
cd lisvy
cargo build --release
./target/release/lisvy
Quick Start
Start the REPL
lisvy
Lisvy REPL v0.1.0
Type (exit) or Ctrl+C to quit
lisvy> (+ 1 2 3)
6
lisvy> (define (square x) (* x x))
lisvy> (square 5)
25
Run a File
lisvy program.lisp
Language Guide
Data Types
| Type | Examples |
|---|---|
| Number | 42, 3.14, -7 |
| String | "hello world" |
| Boolean | true, false, #t, #f |
| List | (list 1 2 3), (quote (a b c)) |
| Nil | nil |
Arithmetic
(+ 1 2 3) ; => 6
(- 10 3) ; => 7
(* 2 3 4) ; => 24
(/ 10 2) ; => 5
(mod 7 3) ; => 1
Comparison
(= 1 1) ; => true
(< 1 2) ; => true
(> 2 1) ; => true
(<= 1 1) ; => true
(>= 2 1) ; => true
Variables
(define x 10)
(define name "Lisvy")
Functions
; Named function
(define (square x) (* x x))
; Lambda (anonymous function)
(lambda (x) (* x x))
; Immediately invoked
((lambda (x) (* x x)) 5) ; => 25
Conditionals
(if (> x 0)
"positive"
"non-positive")
Local Bindings
(let ((x 10)
(y 20))
(+ x y)) ; => 30
Lists
(list 1 2 3) ; Create a list
(car (list 1 2 3)) ; => 1 (first element)
(cdr (list 1 2 3)) ; => (2 3) (rest)
(cons 0 (list 1 2 3)) ; => (0 1 2 3)
(null? (list)) ; => true
Higher-Order Functions
; Map - apply function to each element
(map (lambda (x) (* x 2)) (list 1 2 3))
; => (2 4 6)
; Filter - keep elements matching predicate
(filter (lambda (x) (> x 2)) (list 1 2 3 4 5))
; => (3 4 5)
; Reduce - fold list into single value
(reduce + (list 1 2 3 4 5))
; => 15
(reduce + (list 1 2 3) 100) ; with initial value
; => 106
Examples
Factorial
(define (factorial n)
(if (<= n 1)
1
(* n (factorial (- n 1)))))
(factorial 10) ; => 3628800
Fibonacci
(define (fib n)
(if (<= n 1)
n
(+ (fib (- n 1)) (fib (- n 2)))))
(fib 10) ; => 55
FizzBuzz
(define (fizzbuzz n)
(define (fb i)
(if (<= i n)
(begin
(print
(if (= 0 (mod i 15)) "FizzBuzz"
(if (= 0 (mod i 3)) "Fizz"
(if (= 0 (mod i 5)) "Buzz"
i))))
(fb (+ i 1)))
nil))
(fb 1))
(fizzbuzz 20)
Sum of Squares
(define numbers (list 1 2 3 4 5))
(reduce +
(map (lambda (x) (* x x)) numbers)
0)
; => 55
Reference
Special Forms
| Form | Syntax | Description |
|---|---|---|
define |
(define name value) |
Define a variable |
define |
(define (name args...) body) |
Define a function |
lambda |
(lambda (args...) body) |
Anonymous function |
if |
(if cond then else?) |
Conditional |
let |
(let ((name val)...) body) |
Local bindings |
begin |
(begin expr...) |
Sequence expressions |
quote |
(quote expr) |
Unevaluated data |
Built-in Functions
| Category | Functions |
|---|---|
| Arithmetic | +, -, *, /, mod, % |
| Comparison | =, <, >, <=, >= |
| Logic | not |
| Lists | list, car, cdr, cons, null? |
| Higher-order | map, filter, reduce |
| I/O | print |