prehistory of m4

2012-05-30 Thread Doug McIlroy
machine instructions. Strachey was a brilliant programmer! The three predecessors mentioned above were, in chronological order, written in Snobol 3, Fortran, and Ratfor, so their source code looked far less similar than their behaviors. Doug McIlroy

Better way to interpret $N as dollars, not macro argument?

2014-08-14 Thread Doug McIlroy
I ran into a problem where $N is interpreted as a macro argument, but I wanted a dollar amount. A well constructed document likely doesn't interleave macro definitions with the text that contains the dollar signs you want to protect. In that case an easy fix is to transliterate the literal

Re: Use m4 to change a file in-place

2016-04-10 Thread Doug McIlroy
A special option for each command, e.g. -o in sort and --in-place

tail recursion

2017-07-04 Thread Doug McIlroy
I have been writing a lot of recursive m4 macros lately, and have been disappointed to see that m4 doesn't recognize tail calls and drop the dead stack frame when one occurs. A vivid example is to watch memory usage for this trivial example. define(x,`x') x() It needlessly eats

one input producing multiple output

2018-02-19 Thread Doug McIlroy
> is the answer to do this in multiple passes with different sets of macros? Other possibilities: 1. A single output stream interspersed with diversion tags to be postprocessed by, say, an awk script to distribute it to the several files. 2. Use syscmd to deliver fragments to files: "echo stuff

A little m4 puzzle

2018-11-10 Thread Doug McIlroy
Consider this predicate on strings. define(eq,`define(`_$1',F)define(`_2',T)_$1') eq(x,y) yields T or F according as strings x and y are the same or different. (The strings may contain only characters allowed in macro names). The puzzle: If you omit inner quotes from the definition, eq(A,A)

Re: portability of quote marks

2019-02-02 Thread Doug McIlroy
> I've had occasion to change the left / opening and right / closing quite > in m4 a few times. I usually change it to a left / opening and right / > closing bracket / brace, which ever is best for what I'm doing. Useful feedback. Even "at home" with ASCII m4's left-quote character causes

Re: Problems installing M4 on windows 7

2020-04-19 Thread Doug McIlroy
It's hard to conceive how you got bash bu not make. Try "which make". If that comes up dry, get a copy of make from wherever you got bash. If it says you have make, then you have a strange $PATH, or the install script is playing with it. The latter is unlikely in an ordinary gnu install such as

An interesting demo

2020-08-27 Thread Doug McIlroy
For a demonstration of the power of m4 stripped to the bare minimum--no builtins other than `define'--see www.cs.dartmouth.edu/~doug/barem4.txt. (Because browsers may not like .m4 files, it's called .txt--but is not Windows format.) Well-commented code builds quickly from nothing to binary