m4th /ˈɛmfɔɹθ/ is a Forth dialect and text preprocessor similar in goals to the m4 macro processor.
Like m4, it is built around the concept of streams and, as such, it opts to not implement word sets for managing "string" data types or memory allocation.
Unlike m4, it has a more straightforward syntax informing the interpreter what is and is not to be interpreted: any line not beginning with the control character
^ is always passed literally to the current output stream.
m4th's syntax makes it much more predictable; you will never have to worry about accidentally calling a word. The interpretation rules for the preprocessor are stated tersely as follows:
If a line begins with a
^not immediately followed by a second, pass the line to the Forth interpreter. If the
^is followed by a second, discard it and pass the remaining line to the current output.
If a line ends with a
^not immediately preceded by a second, pass the line to the current output stream without any line-break characters. If the
^is preceded by a second, discard it and pass the remaining line to current output (including any line-break characters).
These simple rules make it difficult to invoke the Forth interpreter in cases where the author doesn't explicitly want to.
Further discussions of m4th's functionality on this page will assume a basic understanding of Forth.
m4th's streams are very similar to m4's.
You may divert to any integer-numbered stream with
divert and flush a stream to the current output stream with
fresh word, which returns a number corresponding to a stream which has never been used or previously returned by a call to
fresh, is provided as a convenience.
Definitions in m4th work very similarly to standard Forth; however, the definition word has been changed from
: (colon) to
page work in progress