oclisp: minimal lisp interpreter in ocaml (2002)

This is oclisp (ocaml lisp), which is a basic lisp interpreter inspired mainly by emacs lisp. It is provide only symbol atoms (no integers, string etc) and cons cells. It is dynamically scoped, and garbage collection is piggybacked from the ocaml runtime. It was written to explore the lisp language, and to evaluate some of the claims made by lisp fans!

Also, please have a look at gocaml, my frontend for GMP Go engines, written in ocaml. You can find lots more cool ocaml software at the ocaml links database and the caml humps.

What can it do?

You can’t use it for much, because it’s so simple. It’s probably most useful for learning how a lisp interpreter works (which is why I wrote it in the first place). As an example of what you can do, here’s a sample session, with user input followed by ‘=>’ then the result:

(car '(a b c)) => a
(cdr '(a b c)) => (b c)
(cons 'a 'b)   => (a . b)

(setq b 'foo)  => foo
b => foo

(defun foo (x) x) => foo
(foo 'a) => a

(cond (nil 'a) (t 'b)) => b

(defun length (l) (if (equal l nil) nil (cons 't (length (cdr l))))) => length
(length nil) => nil
(length '(a)) => (t)
(length '(a b c d e)) => (t t t t t)

(let ((x 'a) (y '(b c))) (cons x y)) => (a b c)

(setq f 'cons) => cons

(funcall f 'a nil) => (a)


You can download the source (15k) for oclist-0.5 here or you can browse the sources online.