» Friday, 11 February A.D. 2011
introducing nibbles
Steven Haflich, in an old Usenet posting, said:
The most pernicious failing of the ANA in my opinion is the refusal to admit the reality that computers deal in numeric bytes and characters with specific formats and codings. A portable ANSI CL program cannot write binary information to a socket or disk file that would be portably readable by another language platform, even a different Common Lisp, and even on the same system. A portable CL program cannot write characters and/or binary numbers of varying format to a single socket or stream. C and Java have no such problems, and portable programs can interact (modulo a little care about endianness byte order)...
If the language were redesigned today, I would like to see the definition get a lot closer to the realities of underlying platforms -- recognize that 8-bit-bytes have an important reality unshared by 9-bit bytes, recognize that real streams have endianess and need to have arbitrary varying datatypes passed through them,...
I have been writing a small library, nibbles, to address some of the shortcomings of Common Lisp in the above area. Specifically, nibbles features accessors on octet vectors for 16-, 32-, and 64-bit signed and unsigned integers in both endiannesses, and readers and writers from octet streams for the same. On x86oid SBCL, it also features efficient, optimized inlined versions of the vector accessors for simple vectors.
Code for reading and writing floats in various endiannesses is also present in the library, but has not been tested and is not exported in this release. Such support is planned for a future release.
Please check out the library, send feedback, and send patches if there are features you'd like to see added or bugs that need to be fixed. (It'd be great to have optimized inlined vector accessors for CCL, for instance...)
posted by Nate @ 10:48PM