September 13th, 2024

Lisp implemented in Rust macros

The `lisp-in-rs-macros` project is a Rust-based Lisp interpreter using macros, supporting compile-time evaluation and various constructs, but lacking explicit recursion. Future updates may include `letrec` support.

Read original articleLink Icon
CuriosityFrustrationExcitement
Lisp implemented in Rust macros

The `lisp-in-rs-macros` project is a simple Lisp interpreter implemented in Rust using declarative macros. It features the `lisp!` macro, which allows users to write Lisp expressions that are evaluated at compile time, such as `lisp!(CAR (CONS (QUOTE A) (QUOTE (B))))`, which expands to "A". The interpreter is concise, comprising fewer than 250 lines of code, and supports various Lisp constructs including `DEFINE`, `QUOTE`, `LAMBDA`, `LET`, `PROGN`, `CAR`, `CDR`, `CONS`, `LIST`, `EQ`, `ATOM`, and `APPLY`. However, it does not support explicit recursion directly, although recursive behavior can be achieved through lambda functions. The repository includes examples, including a quine, demonstrating the use of the `lisp!` macro. Limitations include the lack of support for dotted lists and recursive definitions in the `DEFINE` form. The author intends to enhance the interpreter by adding features like `letrec` and recursive definitions in the future. Additional resources for functional programming and language implementation are also provided in the repository.

- The `lisp-in-rs-macros` project is a Lisp interpreter built with Rust macros.

- It allows compile-time evaluation of Lisp expressions using the `lisp!` macro.

- The interpreter supports various Lisp constructs but lacks explicit recursion.

- Future enhancements may include support for `letrec` and recursive definitions.

- The repository contains examples and resources for further learning.

AI: What people are saying
The comments on the `lisp-in-rs-macros` project reflect a mix of opinions and observations about the implementation and its implications.
  • Some users express concerns about the complexity of Rust and its impact on the simplicity of Lisp.
  • There are discussions about limitations in defining symbols, particularly regarding the use of dashes in identifiers.
  • Users are curious about the memory safety and borrow checker features of Rust in relation to the Lisp implementation.
  • Several comments highlight enthusiasm for the project, with users finding it fun and interesting.
  • References to existing Lisp rules and comparisons to other languages like C++ are made, indicating a broader context of programming language discussions.
Link Icon 15 comments
By @duetosymmetry - 7 months
Greenspun's tenth rule strikes again! https://en.wikipedia.org/wiki/Greenspun%27s_tenth_rule
By @celeritascelery - 7 months
I tried doing something similar to this once. I ran into an issue where I couldn’t define symbols with a dash in them (DEFINE MY-FN…). This is because rust will split the tokens on a dash. It was a small thing, but it meant I couldn’t just copy and paste snippets from a real lisp, I had to transform everything to underscore. Is it the same in your implementation?
By @gleenn - 7 months
I wish there was a well-supported Lisp in Rust, not just the macros. I wonder how much memory safety you would retain or lose being based in Rust. Is it even possible to leverage the borrow checker any any sane way?
By @p4bl0 - 7 months
That was fun. Thanks for sharing!
By @krick - 7 months
Everyone is supposed to be cheering for how "fun" it is, but every time I see anything like that I cannot help but think, that I hate the fact it can be implemented in Rust. It never truly was a simple language, but I think it started as something way more manageable than what it has become.
By @brundolf - 7 months
Wow and it uses macro_rules
By @meindnoch - 7 months
But C++ is not a sane language because templates are Turing-complete, right?
By @djha-skin - 7 months
Obligatory reference to Carp[1], the lisp that uses borrow checking; the "rust" of lisps.

1: https://github.com/carp-lang/Carp

By @elif - 7 months
Hmmmmmmm.... Rustemacs?
By @Validark - 7 months
This is super awesome!