Updated 2018-09-28 13:17:36 by PeterLewerin

m4 is a general-purpose string substitution language. It provides a more general macro facility than the C preprocessor, and was first really publicised as the macro processor for Ratfor in the book Software Tools. It's a sophisticated language, but tricky to use because there's no unique substitution symbol to distinguish macros from ordinary running text.

Description  edit

GNU m4 is the de-facto standard implementation. The manual can be found at [1].

textutil::expand is a Tcl-based alternative. For others, see Template and Macro processing and macro.

DKF: M4 is Turing-Complete, but only really used for autoconf hacking now (and that's a fairly heavily modified version).

Peter da Silva: It's also used in sendmail for automating the generation of config files.

Back around '82, after I left Berkeley, I was using RSX-11 and feeling UNIX-starved. I took a copy of Software Tools and implemented everything in it from Ratfor through ed. When I implemented macro I renamed all the internal symbols so they began with a dollar sign. This made a huge difference in the usability of the language.

LV: So, are there enough benefits to m4 to make it worth a developer's time to use it with Tcl to write sort of metacode, which would be expanded before execution?

In May 2005, Lars H suspects the answer is: "No, it's not worth it. But since m4 happened to be in the right place at the right time (the birth of autoconf), it has become canonized."

AMG: Kinda like Java and Flash on the Web?

escargo 2005-05-28: I once received several technical reports (I believe from Bell Labs, but I could be wrong) about different software they had made available, and one of them was for the m6 macro processor. I don't know how m4 and m6 differred (nor what happened to m5), but I used to be an avid follower of macro language development (primarily for the purposes of software portability). Anybody else remember anything about m6?

EMJ 2014-01-22: Actually, m6 is older than m4, see http://www.gnu.org/software/m4/manual/m4.html#History .

AMG: I like to think that "m4" is a silly abbreviation for "macro", in the same way that "l10n" and "i18n" are abbreviations for "localization" and "internationalization". I also like to think that "L-3" (the name of my company) is an abbreviation for "Link" (the name of my division), even though it's not actually true. ;^)

htm4l was a very early (late 1990s) html authoring tool which is apparently still in some use (or at least the site is still up -- nostalgia, maybe?). It consists of a library of html-producing macros for m4. [name redacted] used it for the first version of the web content management system for the high school where he was webmaster at the time, and kept a separate development branch of htm4l going for a while. Using m4 with htm4l was a vast improvement on writing raw html (at least when managing a number of pages at the same time without the benefit of css etc; html is of course good enough for one or two pages), but not as good as using a scripting language for the task.