mumble

A Lisp written in C, following the *Build Your Own Lisp* book
Log | Files | Refs | README

commit 5c624faca981069cf7d91fdbf1db607b5852875c
parent e7f964c1addf16dc77f15aabe10d4f71cb48d6df
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Tue,  2 May 2023 22:08:21 -0400

add README.

Diffstat:
M.gitignore | 1+
AREADME.md | 77+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mmumble | 0
Msrc/mumble.c | 10++++++----
4 files changed, 84 insertions(+), 4 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,3 +1,4 @@ /src/mpc/.git /src/mpc/.git/** +/src/_mumble.c diff --git a/README.md b/README.md @@ -0,0 +1,77 @@ +# Mumble: A lisp in C + +## About + +This is a Lisp written in C. It follows the outline in this [Build Your Own Lisp](https://buildyourownlisp.com/chapter11_variables) book, though it then adds some small tweaks and improvements and quality of life improvements: + +- A makefile +- Configurable verbosity levels +- Different and perhaps slightly more elegant printing functions +- A slightly different approach to evaluating functions +- Capturing Ctrl+D + +Overall this might be mostly of interest as a pointer to the book that this is originally based on. And to readers of that same book, I'd be curious to see what you ended up with. + +## Installation and usage + +### Dependencies + +This depends on [editline](https://github.com/troglobit/editline), which can be installed on Debian/Ubuntu with: + +``` +git clone https://github.com/troglobit/editline +./autogen.sh +./configure +make all +sudo make install +ldconfig +``` + +Readers might also find it interesting to compile it with [tiny c compiler](https://bellard.org/tcc/) rather than gcc, as it is significantly faster. + +### Compilation + +``` +git clone https://github.com/NunoSempere/mumble +make +# sudo make install # +``` + +### Usage + +Simply call the `./mumble` binary: + +``` +./mumble +``` + +## Example usage + +``` +mumble> (1 2 3) +mumble> { 1 2 3 } +mumble> head (1 2 3) +mumble> { head (1 2 3) } +mumble> tail { 1 2 3 } +mumble> list ( 1 2 3 ) +mumble> eval { head {1 2 3} } +mumble> (eval { head {+ tail head } } ) 1 2 3 +mumble> len {1 2 3} +mumble> join { {1 2} {3 4} } +mumble> def { {x} { 100 } } +mumble> x +mumble> def { { a b c } { 1 2 3} } +mumble> * a b c +mumble> - a b c +mumble> / a b c +mumble> VERBOSITY=0 +mumble> VERBOSITY=1 +mumble> VERBOSITY=2 +``` + + +## Gotchas + +This doesn't currently run on Windows. But it easily could, with [preprocessor statements from the book]. + + diff --git a/mumble b/mumble Binary files differ. diff --git a/src/mumble.c b/src/mumble.c @@ -596,7 +596,7 @@ lispval* builtin_list(lispval* v, lispenv* e) lispval* builtin_len(lispval* v, lispenv* e) { - // tail { 1 2 3 } + // len { 1 2 3 } LISPVAL_ASSERT(v->count == 1, "Error: function len passed too many arguments"); lispval* source = v->cell[0]; @@ -960,7 +960,8 @@ int main(int argc, char** argv) print_lispval_tree(env->vals[0], 2); if (VERBOSE) printfln("\n"); - // Initialize a repl + + // Initialize a repl int loop = 1; while (loop) { char* input = readline("mumble> "); @@ -1007,11 +1008,12 @@ int main(int argc, char** argv) } delete_lispval(answer); if (VERBOSE > 1) - printfln("Answer after deletion: %p", answer); + printfln("variable \"answer\" after deletion: %p", answer); // delete_lispval(answer); // do this twice, just to see. //if(VERBOSE) printfln("Deleting this lispval:"); // if(VERBOSE) print_lispval_tree(l,2); - delete_lispval(l); + + // delete_lispval(l); // if(VERBOSE) printfln("Deleted that ^ lispval"); // ^ I do not understand how the memory in l is freed. // delete the ast