Skip to content

n-lisp is a small Lisp interpreter written in C as a pet project

Notifications You must be signed in to change notification settings

red-bashmak/n-lisp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

n-lisp

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

Usage

n-lisp can be used in three different modes:

  1. REPL Mode
  2. Script Mode
  3. Stdin Mode

REPL 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
10

Write .exit or .quit command to REPL to exit from it.

$ n-lisp
n-lisp> .exit

Script Mode

Provide a Lisp script file as an argument to the n-lisp command to execute the expressions in the file.

$ n-lisp file.lisp

Stdin Mode

Use the - argument to read Lisp expressions from standard input, which can be useful for piping input to the interpreter.

$ echo '(- 12 5)' | n-lisp -
7

Standard Library

n-lisp looks for a standard library file in the following locations, in order:

  1. $N_LISP_HOME/lib/library.lisp
  2. $PWD/lib/library.lisp
  3. $HOME/.local/lib/n-lisp/library.lisp

If the standard library file is found, it will be automatically loaded when the interpreter starts.

Build

To build n-lisp, follow these steps:

  1. Clone the n-lisp repository.
  2. Compile the n-lisp interpreter using make.
  3. The binary will be located in the bin directory.
  4. The standard library is located in the lib directory at the root of the project.

Caveats

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.

Future Improvements

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 😉.

Contributing

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.

About

n-lisp is a small Lisp interpreter written in C as a pet project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published