Hacker News new | ask | show | jobs
by MatthiasPortzel 754 days ago
> a small macro system for WAT, that bootstraps a slightly more highlevel lisp dialect

Lisp traditionally has immutable data structures and a garbage collector, in which case I would consider it more complicated than LO.

I would be very interested if it’s possible to create an extremely simple garbage collector or an ergonomic Lisp that isn’t garbage collected, but a solution doesn’t spring to mind.

6 comments

A classic mark-and-sweep GC for a heap of uniform structs (like cons-pairs) can be implemented in a few lines of code. Garbage collection is not inescapably complicated, it just gets more challenging as you impose more constraints: multithreading, generations, compaction, minimizing bookkeeping overhead, etc.
> Lisp traditionally has immutable data structures

Can you provide a source for this? Common Lisp and its predecessors certainly do not have immutable data structures out of the box. The usual data structures are cons cells, lists (composed of cons cells anyway), vectors, and hash tables.

> I would be very interested if it’s possible to create an extremely simple garbage collector or an ergonomic Lisp that isn’t garbage collected, but a solution doesn’t spring to mind.

PreScheme immediately comes to mind for me as does ulisp. The latter in particular is designed for microcontrollers with limited memory.

While I'm a huge fan of immutable persistent datastructures, I don't think that they are a neccesity.

And linked lists with reference counting are really easy to do, and don't have any leaks if you don't allow cons cell abuse. (which would mess with immutablity anyways)

You could also do linear types like carp [0], or you could just do manual memory management.

I feel like most people will call something with macros and s-expressions, a reasonable, if brutalist, lisp.

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

Pairs in Lisp are mutable, traditionally, and there are other mutable data types like vectors. For targeting wasm only there's no need to figure out a GC solution as that is something the host provides in wasm 2.0.
You could probably do something similar to what Roc is doing: https://www.roc-lang.org/
That much be a very special kind of Lisp, given the amount of variations since the Lisp 1.5 Programmer's Manual came to be.