I use m4 to generate my ssh config files. Otherwise managing the complexity of hundreds of servers over multiple subdomains all with different requirements for access and authentication would be prohibitive, especially given that openssh's config format only has a cursory understanding of how to define patterns with regex or cidr.
Nah, that's what I meant. It does $-expansion and that's it. If you need conditionals and loop you need templates and macros like others are saying: m4, cpp, handlebars, whatever.
I use it as a low-brain template engine to do only that.
They have different design philosophies, but dhall[1] will generally do that sort of thing, and anyone who has dabbled with functional programming and hates baroque syntax common to many languages from the early days of computing may prefer dhall over something like m4.
Of course you are right and hundreds of such tools exist. The only reason we are talking about m4 here is that is basically everywhere for legacy reasons.
Correct. I was motivated to use m4 to solve the problem I had, because m4 is ubiquitous. I wanted to know more about it, and I wanted my config files to be generatable on any machine where I spend some time.
Is anyone aware of other general purpose text manipulation tools concerning documentation within source files? I've been trying to find something like JSDoc that I can use to get some editor hints around parameter types, return values, etc.
(Or maybe you're looking for something totally different; I'm not aware of anything that uses literate programming to feed hints back into an editor, although I'm sure someone has made emacs do it, probably using org mode;])
Wanted a template script recently. I thought for a bit about it and realized that PHP is pretty perfect for the job. Worked well for simple dynamic templates, and no dependencies outside of PHP.
I remember a sysadmin doing the same thing at a previous job (I think he used it for generating PXE boot scripts or something like that) - as you say, great for simple dynamic templates and PHP was the only dependency.
Schools don't teach macro languages is probably the biggest problem.
Before YAML or Dockerfiles, it was the way to declare state and reduce complexity for sysadmins. Basically, any time you had data that needed multiple projections (eg. hosts to forward and reverse zonefiles), you reached for m4. The same went for unwieldy configs (apache, sendmail, etc.).
Culturally, macro languages seem to be just learned ad-hoc, ie. how many here have had a class in m4 or TeX?
Gnu M4 manual works well, while for TeX there's the Gentle Introduction.
For an abstract, design/implementation introduction, though? There isn't. We don't learn about macro languages just as we don't learn about domain specific languages.
23 comments
[ 2.9 ms ] story [ 73.8 ms ] threadI use it as a low-brain template engine to do only that.
[1] https://dhall-lang.org/
Notes on the M4 Macro Language (2008) - https://news.ycombinator.com/item?id=22757645 - April 2020 (59 comments)
Related:
M4 as a templating language (2020) - https://news.ycombinator.com/item?id=27994092 - July 2021 (112 comments)
M4 (computer language) - https://news.ycombinator.com/item?id=17781062 - Aug 2018 (26 comments)
Ask HN: Do you use M4 in production? - https://news.ycombinator.com/item?id=15870100 - Dec 2017 (1 comment)
M4BASIC – A BASIC to C converter written in M4 - https://news.ycombinator.com/item?id=10748131 - Dec 2015 (1 comment)
(Or maybe you're looking for something totally different; I'm not aware of anything that uses literate programming to feed hints back into an editor, although I'm sure someone has made emacs do it, probably using org mode;])
Before YAML or Dockerfiles, it was the way to declare state and reduce complexity for sysadmins. Basically, any time you had data that needed multiple projections (eg. hosts to forward and reverse zonefiles), you reached for m4. The same went for unwieldy configs (apache, sendmail, etc.).
Culturally, macro languages seem to be just learned ad-hoc, ie. how many here have had a class in m4 or TeX?
I haven't, but could be interested; are there any good tutorials or such that you might suggest?
For an abstract, design/implementation introduction, though? There isn't. We don't learn about macro languages just as we don't learn about domain specific languages.