REPLisp is a modern Lisp-inspired programming language implemented in Rust with no external dependencies. It features a clean syntax, powerful metaprogramming capabilities, and a focus on simplicity and expressiveness.
- Pure Rust implementation with zero external dependencies
- Interactive REPL (Read-Eval-Print Loop)
- Modern Lisp syntax with S-expressions
- First-class functions and closures
- Lexical scoping
- Homoiconicity (code as data)
- Tail call optimization
- Comprehensive error reporting
To build REPLisp, you'll need Rust and Cargo installed. Clone this repository and run:
cargo build --releaseThe compiled binary will be available at target/release/replisp.
To start the interactive REPL:
cargo runTo execute a REPLisp script file:
cargo run -- path/to/script.lispREPLisp uses S-expressions (symbolic expressions) where operations are written in prefix notation:
; Numbers
42
3.14159
; Strings
"Hello, World!"
; Symbols
foo
+
my-variable
; Comments start with semicolon
; This is a commentFunction calls use parentheses with the function name first:
(+ 1 2 3) ; Addition: 6
(* 4 5) ; Multiplication: 20
(print "Hello") ; Print to stdoutLists are fundamental data structures:
'(1 2 3 4) ; Quoted list
(list 1 2 3 4) ; Constructed list
(cons 1 '(2 3)) ; Prepend element: (1 2 3)
(car '(1 2 3)) ; First element: 1
(cdr '(1 2 3)) ; Rest of list: (2 3)Define variables with def:
(def x 10)
(def name "Alice")
(def my-list '(1 2 3))Define functions with defn:
; Named function
(defn square (x)
(* x x))
; Anonymous function (lambda)
(lambda (x y) (+ x y))
; Function with multiple expressions
(defn greet (name)
(print "Hello,")
(print name))Use if for conditional expressions:
(if (> x 0) "positive" "non-positive")
; Multi-way conditionals with cond
(cond
((< x 0) "negative")
((> x 0) "positive")
(else "zero")); Map function over list
(map square '(1 2 3 4)) ; (1 4 9 16)
; Filter list elements
(filter (lambda (x) (> x 0)) '(-1 2 -3 4)) ; (2 4)
; Reduce/fold
(reduce + 0 '(1 2 3 4)) ; 10Create local bindings with let:
(let ((x 10)
(y 20))
(+ x y)) ; 30Define macros for code transformation:
(defmacro when (condition . body)
`(if ,condition (do ,@body)))
(when (> x 0)
(print "positive")
(print "number"))+,-,*,/- Basic arithmeticmod- Modulo operationabs- Absolute valuemin,max- Minimum/maximum
=,<,>,<=,>=- Comparison operatorseq?- Object equality
list- Create listcons- Prepend elementcar,cdr- First element, rest of listlength- List lengthappend- Join listsreverse- Reverse list
number?,string?,symbol?,list?- Type checkingnull?- Check for empty list
print- Print to stdoutread- Read from stdin
Special forms are evaluated differently from regular functions:
quoteor'- Prevent evaluationdef- Define variabledefn- Define functionif- Conditionalcond- Multi-way conditionallet- Local bindingslambda- Anonymous functiondefmacro- Define macro
(defn factorial (n)
(if (<= n 1)
1
(* n (factorial (- n 1)))))
(factorial 5) ; 120(defn sum-list (lst)
(if (null? lst)
0
(+ (car lst) (sum-list (cdr lst)))))
(sum-list '(1 2 3 4 5)) ; 15(defn apply-twice (f x)
(f (f x)))
(apply-twice (lambda (x) (* x 2)) 5) ; 20REPLisp is under active development. Current focus areas:
- Core language features
- Standard library expansion
- Performance optimizations
- Error handling improvements
- Documentation and examples