association-list

October 28, 2006

Lisp is annoying.

no tags — evan @ 12:49 pm

So, the other day I was read­ing pro­gram­ming blogs, which seems to be the thing do do when you don’t actu­ally want to work, and I ran into Erlang’s facil­ity for binary pat­tern match­ing. Essen­tially it’s a rather nice syntax for taking a wodge (that’s a tech­ni­cal term) of binary data and decom­pos­ing it into vari­ables. 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 inte­ger called monkey from the 9th through 40th bits, a ushort called bazzle, a 4 byte string called arrr (you could spec­ify fur­ther what type of string, I think, if you needed some­thing else), and a binary glob called rest with the rest of packet. I thought that this was pretty neat, and was think­ing that making a nice, gen­eral facil­ity for this in Lisp would make an inter­est­ing 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 read­ing up about how some­one might go about doing some­thing like this when I ran into some­thing in Prac­ti­cal Common Lisp that was more or less exactly what I was think­ing of, expressed in a macro that really isn’t that long. it’s called define-binary-class and gen­er­ates the class and a con­struc­tor that will read in binary data in a sim­i­lar manner to the above. Plus, with some triv­ial mod­i­fi­ca­tions, I’m sure that you could alter it to make either struc­tures or classes and to nest def­i­n­i­tions, which is some­thing that the static syntax of Erlang cannot do.

This, to me, is the pri­mary virtue of Lisp, but it’s some­times frus­trat­ing that most things are so triv­ial in the lan­guage that there’s noth­ing to do as an intro but leap into appli­ca­tion code. This, per­haps, is one of the things that keeps people from get­ting into the lan­guage. You can do any­thing, but it’s either triv­ial or hard (or at least time con­sum­ing). Also, you’re for­ever doing things and then real­iz­ing that the mas­sive stan­dard library already has some­thing that does exactly that. And then there’s the con­stant impe­tus to refac­tor the code into some­thing cleaner, which the macro facil­i­ties of the lan­guage makes easy, fun and pow­er­ful, so the temp­ta­tion to cat-​​hoover away all of your pro­gram­ming time clean­ing up the code is pretty strong. That all of this is exac­er­bated by my lack of abil­ity to think of enthralling soft­ware projects to work on is, I’m sure, incidental.

Comments are closed.