Objective: implement a small Lisp/Scheme language in as little C code as possible.
This is a hobby project for educational purposes, it has bugs and may fail without warning. Pull requests and improvements welcome
The interpreter supports
((lambda (x) (cons x (quote 1))) (quote 7)) (7 . 1)
lambda does not capture free variables (variables that are not passed as arguments and refer to an outer scope). Free variables will resolve to their assigned values in the environment when the body of the lambda is evaluated.
The special forms
quote behave in a typical way:
(if (quote t) (quote 7) (quote 0)) 7
The only types are symbols and pairs.
Non-quoted symbols are looked up in the environment. If they have no associated
value the result is
null; in fact, zero. Because there is no numeric type a
7 will be treated like any other symbol and looked up in the environment.
Note in the examples above how numbers are quoted to prevent that.
The built-in primitives in the environment are:
Also provided is
apply which takes a function and a single list argument:
(apply write (quote ((hello world)))) (hello world) (quote t)
Lists can be built up by
(apply write (cons (cons (quote hello) (cons (quote world) null)) null)) (hello world) (quote t)
Read Eval Print Loop
A REPL is implemented in micro-lisp itself. To try it out in a terminal:
cat repl.lisp - | ./micro-lisp
To exit, press 'control c' to terminate the process.
- argument to
cat to pipe stdin through, otherwise micro-lisp will receive end-of-file.
The source code for the REPL is in
repl.lisp. It implements
eval and provides an environment which resolves symbols to the primitive functions in the underlying micro-lisp interpreter.
Debugging with GDB
.gdbinit file sets the target, breakpoints and runs the executable. Simply run
Pull requests welcome.