Reverse String in M4

Published on 13 August 2025 (Updated: 13 August 2025)

Welcome to the Reverse String in M4 page! Here, you'll find the source code for this program as well as a description of how the program works.

Current Solution

divert(-1)
dnl Commas are intepreted as argument separators, so need to change them to something that
dnl won't appear in the argument and then change them back
define(`escape', `translit(``$1'', `,', `«')')
define(`unescape', `translit(``$1'', `«', `,')')

dnl reverse(str)
define(`reverse', `unescape(_reverse(escape(`$1')))')
define(`_reverse', `ifelse(len(`$1'), 0, , `_reverse(substr(`$1', 1))`'substr(`$1', 0, 1)')')
divert(0)dnl
ifelse(ARGC, 0, , `reverse(ARGV1)')

Reverse String in M4 was written by:

If you see anything you'd like to change or update, please consider contributing.

How to Implement the Solution

No 'How to Implement the Solution' section available. Please consider contributing.

How to Run the Solution

No 'How to Run the Solution' section available. Please consider contributing.