M4 Macros

January 30, 2015

I’ve always had a love/hate relationship with m4 macros. For programming languages that don’t offer macros, or have only a limited form of macros (like C), m4 can be a godsend. Used to their fullest potential, m4 macros enable programmers to write programs that write programs, which can lead to extremely high productivity. And m4 macros aren’t limited to use in programming; I used m4 macros recently when writing my security camera essay (which is what inspired me to write this exercise).

If you’re interested in learning about m4, the original tutorial by Brian Kernighan and Dennis Ritchie is a fine introduction for casual use, the manual for Gnu m4 is complete and definitive, and this short essay by Ken Turner is a little bit insane.

Your task is to use m4 to write some program or transform some text; the purpose is to introduce you to m4 (or re-introduce you if it’s been a long time since your last use), so any task will do. When you are finished, you are welcome to read or run a suggested solution or to post your own solution or discuss the exercise in the comments below.

Advertisement

Pages: 1 2