association-list a veritable mint for dunning-kruggerands

Lisp is annoying

So, the other day I was reading programming blogs, which seems to be the thing do do when you don’t actually want to work, and I ran into Erlang’s facility for binary pattern matching. Essentially it’s a rather nice syntax for taking a wodge (that’s a technical term) of binary data and decomposing it into variables. So:

<< foo:8, monkey/integer, bazzle:16, arrr:4/string, rest/binary >> = packet

will get you ubyte called foo with the first 8 bits of packet, an unsigned integer called monkey from the 9th through 40th bits, a ushort called bazzle, a 4 byte string called arrr (you could specify further what type of string, I think, if you needed something else), and a binary glob called rest with the rest of packet. I thought that this was pretty neat, and was thinking that making a nice, general facility for this in Lisp would make an interesting project, at least for me, because even though I know a fair amount about Lisp, I haven’t really used it that much. In any case, I was reading up about how someone might go about doing something like this when I ran into something in Practical Common Lisp that was more or less exactly what I was thinking of, expressed in a macro that really isn’t that long. it’s called define-binary-class and generates the class and a constructor that will read in binary data in a similar manner to the above. Plus, with some trivial modifications, I’m sure that you could alter it to make either structures or classes and to nest definitions, which is something that the static syntax of Erlang cannot do.

This, to me, is the primary virtue of Lisp, but it’s sometimes frustrating that most things are so trivial in the language that there’s nothing to do as an intro but leap into application code. This, perhaps, is one of the things that keeps people from getting into the language. You can do anything, but it’s either trivial or hard (or at least time consuming). Also, you’re forever doing things and then realizing that the massive standard library already has something that does exactly that. And then there’s the constant impetus to refactor the code into something cleaner, which the macro facilities of the language makes easy, fun and powerful, so the temptation to cat-hoover away all of your programming time cleaning up the code is pretty strong. That all of this is exacerbated by my lack of ability to think of enthralling software projects to work on is, I’m sure, incidental.

<-- Notice Smelling the unsmellable -->