Little Languages

Last month, I wrote about one of John Bentley’s Programming Pearls columns in the Communication of the ACM. Someone has posted another column, this one on Little Languages. I remember reading the column in More Programming Pearls; it instilled in me a way of looking at certain problems that I’ve used throughout my career.

It’s surprising how often a problem can be easily solved by writing a little language to transform the data you have into a form suitable for some other existing program that can do all the heavy lifting. Bentley gives the example of chem, a small awk program that took the description of some chemical as input and output a pic program that could be used as input to troff to typeset the standard graphical representation of the chemical. Thus he (and Brian Kernighan) chained together two little languages to produce a useful input to troff to do something that I’m sure Joseph Ossanna never envisioned when he wrote troff.

Early in my career, I did something similar. I was part of a small remote team working on Unix systems. My personal computer was running FreeBSD, which at that time did not have anything like OpenOffice. The HR trolls demanded time sheets that were printed from an Excel spreadsheet. Since I couldn’t do that, I wrote an awk program to take my task times as input and output tbl (another troff little language preprocessor) commands that troff then typeset as a reasonable facsimile of the Excel spreadsheet. I’ve used the same trick over and over: write a simple program to produce input to some larger program to produce the needed output.

Take a look at Bentley’s column1. Perhaps you’ll learn a new way or working too.

Footnotes:

1

The PDF of the ACM article is a little confusing. Pages 714 and 715 are a sidebar meant to be read separately but it comes right in the middle of the main text and it’s easy to get lost.

This entry was posted in General and tagged , . Bookmark the permalink.