An interpreter for a custom lisp dialect.
The core language should be as simple as possible, complex features should be implemented in terms of the primitives where possible and reasonable. Let can be implemented with lambda, loops can be implemented with recusion, etc.
The language should support an optional static type system.
This lisp is intended to be similar to Emacs lisp, but functions and values are unified into a single namespace like in scheme.
There is only one equality function, “=”, no eq, eql, equal, etc.
This lisp also has an optional hindley-milner based type system, and built-in sum types.
This language is very unstable and many things are not implemented yet, and everything is subject to change.
NOTE: You will need rust’s nightly toolchain installed to build this project.
git clone https://github.com/Jturnerusa/lisp
cd lisp
cargo buildCurrently, the core lib is passed as an environment variable.
export CARPET_LISP_PATH="$PWD/lib/lisp"Sample lisp for testing:
(require list)
(defun (fib int -> int) (n)
(if (< n 2)
n
(+ (fib (- n 1))
(fib (- n 2))))))
(named-let loop ((n 1))
(print (fib n))
(if (< n 10)
(loop (+ n 1))
nil))Run the sample:
cargo run --bin eval sample.lispThis should result in a fibonaci sequence up to 10 indices:
1 1 2 3 5 8 13 21 34 55
Sum types, structs and generics
; 'a is a type parameter
(deftype tree (branch tree tree) (leaf 'a))
(defun (tree-map (fn 'a -> 'b) (tree 'a) -> (tree 'b)) (fn tree)
(typecase tree
((tree-branch l r)
(tree-branch (tree-map l) (tree-map r)))
((tree-leaf a)
(tree-leaf (fn a)))))
(defstruct dog
(name string)
(age int))
(defun (dog-bark dog -> nil) (dog)
(print (dog-name dog))
(print (dog-age dog)))
(dog-bark (make-dog "lily" 4))List of native functions:
+-*/conscarcdrlistapplycons?function?symbol?string?int?char?nil?applylambdadefmacrodefset!eval-when-compilequoteif- ===
><assertdeclmap-createmap-insert!map-retrievemap-itemsmoduleexportrequiredefstructdeftypeif-let
- More native Functions (string slicing, utils, etc.)
- Pattern matching
- Self hosting
- Full global type inference