Binary S-expressions Lassi Kortela 16 Sep 2019 17:49 UTC

> Might I interest you in a simple "binary S-expressions" format that can
> be converted into textual S-expressions and back? I've been wanting to
> make one for a long time and this would be a perfect application :)
>
> Using varints for all numerical quantities, and encoding all strings
> with a varint length prefix, one gets trivial code with no endianness,
> escaping or whitespace issues and no size limits. Embedding binary blobs
> is trivial. A varint type tag can distinguish between different kinds of
> objects. There are ways to wring more bit density out of all this stuff
> but I would favor simplicity.

I hacked this up:
<https://github.com/lassik/scheme-database-temp/blob/master/binary.sls>

80 lines of Scheme. The "test-binary" program in the same repo shows
that the library can write its own source code as a binary S-expression
and read back equal results :)

TODO: numbers other than integers