Zia responded to my my article on XSLT and declarative programming languages by pointing out that AWK has some declarative features. This is true. An AWK program is structured as a preamble, followed by a collection of rules, followed by a postamble. The rules use a regular expressions for the pattern and an imperative chunk of code for the action. Functions can be defined separately. AWK executes the preamble and then begins processing the lines of text in a file in turn. If a regexp matches, the imperative chunk of code is executed on the line of text that matched. Yet I suspect that for most programmers if didn't feel declarative. Because AWK works on lines of text, it easy for most programmers to envision an implicit foreach-loop surrounding the rules and each rule as a case in a big case statement. Even so, I'd bet most AWK programs were written with a single rule.

Correction: Sean Nolan wrote to tell me the "were" in the last sentence should be "are." I stand corrected. AWK is by no means dead.


Please leave comments using the Hypothes.is sidebar.

Last modified: Thu Oct 10 12:47:20 2019.