n-lisp is a command-line Lisp interpreter that provides a REPL (Read-Eval-Print Loop) and the ability to execute Lisp scripts. This is yet another (n-th) implementation of Lisp, created for fun and learning, without any dependencies other than readline from -ledit. It is currently in development and may contain security vulnerabilities and bugs. However, it works great as a calculator for fairly complex Lisp expressions with macros, but for now you should be careful with recursive functions
n-lisp can be used in three different modes:
- REPL Mode
- Script Mode
- Stdin Mode
Run the n-lisp command without any arguments to start the REPL, where you can interactively write and evaluate Lisp expressions.
$ n-lisp
n-lisp> (+ 1 2 3)
6
n-lisp> (define x 10)
x
n-lisp> x
10Write .exit or .quit command to REPL to exit from it.
$ n-lisp
n-lisp> .exitProvide a Lisp script file as an argument to the n-lisp command to execute the expressions in the file.
$ n-lisp file.lispUse the - argument to read Lisp expressions from standard input, which can be useful for piping input to the interpreter.
$ echo '(- 12 5)' | n-lisp -
7n-lisp looks for a standard library file in the following locations, in order:
$N_LISP_HOME/lib/library.lisp$PWD/lib/library.lisp$HOME/.local/lib/n-lisp/library.lisp
If the standard library file is found, it will be automatically loaded when the interpreter starts.
To build n-lisp, follow these steps:
- Clone the n-lisp repository.
- Compile the n-lisp interpreter using
make. - The binary will be located in the
bindirectory. - The standard library is located in the
libdirectory at the root of the project.
Warning: The current implementation of n-lisp does not optimize tail recursion and other kinds of it, which means that recursive functions may cause a stack overflow. This is an issue that needs to be addressed in future updates.
The following improvements are planned for future versions of n-lisp:
- Optimize tail recursion to prevent stack overflow issues.
- Improve error handling and reporting.
- Expand the standard library with more built-in functions and utilities. It should be enough for run examples from SICP.
- Unification of structs for parsing and evaluating results.
- Replace/improve memory management from the reference counting to GC.
- Refactor eval and apply functions, remove crazy, unnecessary C macros 😉.
Contributions to n-lisp are welcome! If you find any issues or have suggestions for improvements, please create a new issue or submit a pull request on the n-lisp repository.