News for hackers. Stuff that matters.
Re:“Make” as a Static Site Generator by gizmo686 on Sunday September 10, 2023 @10:14AM (#37455940)
There is no such thing as a "pinch of m4". You start a clean project promising that you won't touch m4 this time. Then you add a small m4 invocation to save yourself from some boilerplate.

A year later, when you are trying to figure out why all instances of the word "cat" are silently disapearing from your website, you dig through 5 layers of macro expansions to discover that a junior dev tried implementing a for loop instead of copying it from the manual and messed up the quotation marks.

Having solved the immediate issue, you decide that debbuging your DSL is too hard, so you import M4 macro file you have been copying between projects. You then spend a day replacinf all usages of 'define' with your macro-creating-macro that adds comments to the output enabling your stacktrace generation script to work.

Next project, I am putting down a hard rule: no m4! (Except for maybe that one instance)

Re:“Make” as a Static Site Generator by JoelMcCracken on Sunday September 10, 2023 @11:00AM (#37456432)
Please write more to this story
Re:“Make” as a Static Site Generator by gizmo686 on Sunday September 10, 2023 @11:34AM (#37456828)
Not "this" story. Everything above has happened on several projects. The cat thing comes up because it is tricky to expand two macros next to each other without whitespace. So if you do:

  define(`foo',`hello')
  define(`bar',`world')
  foo bar
  foobar
You will get:

  hello world
  foobar
Working around this gets tricky, so someone inevitably ends up writing a cat-like macro such that you can do

  cat(foo,bar)
To get

  helloworld.
A side effect of this is that now "cat" is really "cat()" which expands to "". You can work around this by doing `cat'. However, if `cat' is used as an argument to another macro (such as a for loop), the quotation only prevents escaping the first time. When the for macro is expanded, the quotation marks are stripped, giving you just "cat", which gets expanded again. A correctly written for macro would add new quotes as needed, but I have never seen someone correctly write such a macro without just copying it.

Not sure if I have seen this interaction specifically with for and cat, but I have seen an interaction like it on almost every project that used m4.

Re:“Make” as a Static Site Generator by mhitza on Sunday September 10, 2023 @11:58AM (#37457068)
You can place an empty "expansion" in that line to get the behavior you want without an additional cat-like function

    foo`'bar
I only know of this feature because recently read the manual page for m4, and it's mentioned rather early in there, but might have been not as well emphasized in past iterations of the manual.
Re:“Make” as a Static Site Generator by gnubison on Sunday September 10, 2023 @11:59AM (#37457085)
For completions sake, though, the easy way to do it is:

    foo`'bar
The empty quotes make foo and bar separate words.
Re:“Make” as a Static Site Generator by js2 on Sunday September 10, 2023 @11:28AM (#37456767)
I've only ever used m4 via autoconf and sendmail configuration files, so I don't know if it's m4 that has the bizarre syntax or whether it's autoconf's and sendmail's use of it. I'm not sure I've ever tried to use m4 directly for anything.
Re:“Make” as a Static Site Generator by m000 on Monday September 11, 2023 @08:29AM (#37466240)
That's why I wrote a "pinch" in the OC. m4 is arguably better than cat as a barebones template engine. The moment you start doing anything beyond simple includes and variable extrapolations, it is time to switch something more modern and robust.

I guess autoconf/sendmail still use m4 because there wasn't anything better at the time that doesn't come with a kitchensink attached.

Re:“Make” as a Static Site Generator by _ache_ on Sunday September 10, 2023 @11:39AM (#37456878)
I know that story too well. Finally, I thought that if I have to code, I should just use a programming language.

Now, I use nodeJS to replace every m4 file with mustache.js and some JS logic and I don't feel limited anymore. The complexity doesn't increase much.