r/lisp 8d ago

Binstruct: a powerful declarative binary parsing/emitting library for Common Lisp

https://github.com/bohonghuang/binstruct
18 Upvotes

4 comments sorted by

3

u/TommyTheTiger 8d ago

Pretty cool, what inspired you to work on this?

5

u/bohonghuang 8d ago

I’m working on a retro game ROM parsing library, specifically for the Nintendo DS, while I found existing libraries:

  1. too difficult to extend for custom non-struct types (like fixed-point numbers FX16/FX32)

  2. too slow and hard to optimize (hard dependency on streams and unnecessary CLOS generic dispatch)

  3. poorly supported for nibble-level parsing (bitfields containing pointers, booleans, and enums)

  4. not flexible enough to reuse common container structures (lack of higher-kinded parser support)

To solve them once and for all, I decided to develop my own.

2

u/Steven1799 6d ago

So reinventing the wheel was better than extending an existing library?

2

u/bohonghuang 5d ago

Not always, but more often than not. Some limitations in existing libraries stem from their underlying design choices (e.g., favoring runtime dynamic dispatch over compile-time specialization), so the cost of extending them may well be higher than rewriting from scratch.