Scum: write me a Scheme-ish

2023-04-20

A wretched hive of scum and villainy

With it being my birthday today, I took a little bit of time to noodle on a pet project. For all the computer science classes I’ve taken, books I’ve read, course notes I’ve looked through, and code I’ve written, reviewed, or perused, I had yet to implement any sort of Lisp-like language myself. Having decided to change that, I’ve been toying around for the last month or so on scum, a Scheme-ish, Lisp-like language implementation. It’s by no means good1 in any sense of the word; it’s incomplete, under-commented, probably loaded with bugs, undoubtedly slow, and profligate with its memory usage. However, as of today, it’s cleared the bar I set for myself for being a reasonable-ish implementation: I can define and call lambdas from the REPL!

How long is a piece of string

There’s not a lot of code currently, so feel free to peruse the repo yourself:

~/github/scum ∃ l
Permissions Size User  Date Modified Git Name
.rw-r--r--@  25k genos 13 Apr 14:58   -- Cargo.lock
.rw-r--r--@   94 genos 13 Apr 14:58   -- Cargo.toml
.rw-r--r--@ 1.1k genos 13 Apr 14:58   -- LICENSE
.rw-r--r--@   56 genos 13 Apr 14:58   -- README.md
drwxr-xr-x@    - genos 20 Apr 15:18   -- scum-lib
drwxr-xr-x@    - genos 13 Apr 14:58   -- scum-repl
drwxr-xr-x@    - genos 20 Apr 13:22   -I target
~/github/scum ∃ tokei
===============================================================================
 Language            Files        Lines         Code     Comments       Blanks
===============================================================================
 Markdown                1            3            0            2            1
 Pest                    1           38           26            8            4
 Rust                    8          628          577            9           42
 TOML                    3           27           23            0            4
===============================================================================
 Total                  13          696          626           19           51
===============================================================================

By no means as succinct as, say tinylisp, nor as complete as the mal implementations, scum consists of

λ>  (define square (lambda (x) (* x x)))
(lambda (x) (* x x))
λ>  (square 39)
1521

I originally started in Haskell, but decided to shift to Rust because I kind of wanted this to be an exercise in satisfying an annoying pedant; Haskell provides so much already, it almost felt like cheating to use it. Besides the aforementioned rustyline crate in scum-repl, I’ve used pest and pest_derive for parsing and thiserror for organizing the sundry reasons things can go wrong. While pest was new to me and has been fun, I’ve used thiserror on other projects at $WORK before; I absolutely would not write any substantial Rust project without it at this point.

Inspirations

I wouldn’t have gotten even this far on scum2 without the help of

Postscript

👋 to the former coworker who enjoined me to blog more! I miss working with you, friend.

  1. It’s the exact opposite of raganwald’s README section, inspiration here↩︎

  2. I didn’t consume all of this recently in my quest to put scum together, but I would almost certainly be remiss in not mentioning these; in fact, I’m probably leaving lots out! ↩︎