mumble

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

README.md (2781B)


      1 # Mumble: A lisp in C
      2 
      3 ## About
      4 
      5 This is a Lisp written in C. It follows the outline in this [Build Your Own Lisp](https://buildyourownlisp.com) book, though it then adds tweaks and quality of life improvements:
      6 
      7 - A makefile
      8 - Configurable verbosity levels
      9 - Different and perhaps slightly more elegant printing functions
     10 - A slightly different approach to evaluating functions
     11 - Capturing Ctrl+D
     12 - Float instead of ints
     13 
     14 Conversely, it doesn't have:
     15 - Function currying
     16 - strings
     17 - Variable arguments
     18 - ...
     19 
     20 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.
     21 
     22 ## Installation and usage
     23 
     24 ### Dependencies
     25 
     26 This depends on [editline](https://github.com/troglobit/editline), which can be installed on Debian/Ubuntu with:
     27 
     28 ```
     29 git clone https://github.com/troglobit/editline
     30 ./autogen.sh
     31 ./configure
     32 make all
     33 sudo make install
     34 ldconfig
     35 ```
     36 
     37 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.
     38 
     39 ### Compilation
     40 
     41 ```
     42 git clone https://github.com/NunoSempere/mumble
     43 make
     44 # sudo make install # 
     45 ```
     46 
     47 ### Usage
     48 
     49 Simply call the `./mumble` binary:
     50 
     51 ```
     52 ./mumble
     53 ```
     54 
     55 ## Example usage
     56 
     57 ```
     58 mumble> (1 2 3)
     59 mumble> { 1 2 3 }
     60 mumble> head {1 2 3}
     61 mumble> { head {1 2 3) }
     62 mumble> tail { 1 2 3 }
     63 mumble> list ( 1 2 3 )
     64 mumble> eval { head {1 2 3} } 
     65 mumble> (eval { head {+ tail head } } ) 1 2 3 
     66 mumble> len {1 2 3}
     67 mumble> join { {1 2} {3 4} }
     68 mumble> def {x} { 100 }
     69 mumble> def {y} 100
     70 mumble> (x y)
     71 mumble> VERBOSITY=2
     72 mumble> def {sq} (@ {x} {* x x})
     73 mumble> sq 44
     74 mumble> VERBOSITY=1
     75 mumble> def {sqsum} (@ {x y} {(+ (sq x) (sq y))})
     76 mumble> sqsum 2 3
     77 mumble> VERBOSITY=0
     78 mumble> def {init} (@ {xs} { list((head xs)) } )
     79 mumble> def {kopf} (@ {xx} { head (list xx) } )
     80 mumble> init {1 2}
     81 mumble> kopf (1 2)
     82 mumble> ifelse 1 2 3
     83 mumble> if 1 2 3
     84 mumble> ifelse 0 1 2 
     85 mumble> if 0 1 2 
     86 mumble> if {1 2 3} (1) (1)
     87 mumble> def {positive} (@ {x} {> x 0})
     88 mumble> def {fibtest} (@ {x} {if (> x 0) {+ x 1} 0 })
     89 mumble> fibtest 2
     90 mumble> def {fibonacci} (@ {x} {if (> x 1) { + (fibonacci (- x 2)) ( fibonacci ( - x 1 ) ) } 1} )
     91 mumble> fibonacci 4
     92 mumble> def {!} (@ {x} { if ( > 1 x) 1 { * x (! (- x 1)) } })
     93 mumble> ! 100
     94 mumble> def {++} (@ {x} { if ( > 1 x) 0 { + x (++ (- x 1)) } })
     95 mumble> ++ 10
     96 mumble>  def {++2} (@ {x} { / (* x (+ x 1)) 2 })
     97 mumble> ++2 10
     98 
     99 ```
    100 
    101 ## To do
    102 
    103 - [x] Define functions
    104 - [x] Define if, = and >
    105 - [x] Build fibonacci function
    106 - [x] Build factorial function
    107 
    108 ## Gotchas
    109 
    110 This doesn't currently run on Windows. But it easily could, with the preprocessor staments from parsing.c [here](https://buildyourownlisp.com/chapter6_parsing).