Quanta is a lightweight Lisp interpreter implemented as an exercise in building interpreters.
Useful discoveries and lessons that I've learned here will benefit ongoing development on my Haven programming language, although Haven and Quanta have different overall goals.
-
Core Lisp Semantics:
- Supports conses and atoms.
- Implements special forms like
quote,lambda,let,cond, anddefine. - Provides primitives for arithmetic (
+,-,*,/), equality (eq?), and list manipulation (cons,car,cdr).
-
Interactive REPL:
- Run Quanta interactively to evaluate expressions and explore its features.
Quanta uses a Lisp syntax where programs are composed of expressions. Here are some examples:
5 ; Integer
"hello" ; String
t ; True
nil ; False
:keyword ; Keyword() ; Empty list
(1 2) ; List with two elements
(1 (2)) ; Nested list
(1 (2 3)) ; Nested list with multiple elements
(1 (2 (3))) ; Deeply nested list
(1 . 2) ; Explicit construction from CAR/CDR pair(defun sqr (x) (* x x)) ; Defines a function `sqr`
(define squared (let ((x 2)) (sqr x))) ; Uses `let` to bind and call `sqr`
(print squared) ; Prints the value of `squared`
(cond ((eq? squared 4) 0) (t 1)) ; Conditional expression(defun repl ()
(begin
(print "lisp> ")
(let ((input (read-line)))
(begin
(print (eval (read input)))
(repl)))))
(repl) ; Starts the REPL(define sum (lambda (n acc)
(cond ((eq? n 0) acc)
(t (sum (- n 1) (+ n acc))))))
(print (sum 10000 0)) ; Ensures TCO worksQuanta uses CMake for building. To build the project, run:
mkdir build
cd build
cmake ..
makeAfter building, you can run the interpreter:
./build/quantaQuanta includes a suite of tests using GoogleTest. To run the tests:
cd build
ctestQuanta is licensed under the MIT License. See the LICENSE file for details.