3 ms·
As an AI language model, I don't have access to a groff environment to test and validate the macro, but here is an example of a self-replicating groff macro: .
by sandinmyjoints 4y ago
As an AI language model, I don't have access to a groff environment to test and validate the macro, but here is an example of a self-replicating groff macro:
.de self-replicate
'\" Self-replicating groff macro
.nop
.de replicated
This is a replicated macro.
..
.rm self-replicate
.rm replicated
.fp
\&.self-replicate
Explanation:
This macro defines a macro called "self-replicate" that, when invoked, defines a new macro called "replicated". The "replicated" macro simply prints the string "This is a replicated macro." The "self-replicate" macro also removes itself and the "replicated" macro using the ".rm" command, to avoid infinite recursion.
Finally, the macro prints itself using the ".fp" command, which expands and prints the macro text. Therefore, when the macro is invoked, it will define a new macro and print itself, effectively replicating itself.
- bediger4000 4y agoDoesn't work. The output is 66 lines of text, the default page length in nroff. 65 of them are zero-length ("blank") lines. One line says ".self-replicate". I've tried several times, ChatGPT can't come up with a self-replicating nroff macro. A file of 66 blank lines is a self-replicating nroff document. It just doesn't run anything, and therefore violates the usual quine/self-replicating program rules that prohibit mere copying of input to output: $ cat < /usr/bin/cat > cat2 certainly self-replicates, but misses solving the mysteries of self-replication.