4

i tried to write a self-replicating program ("quine") in raw (no macros) GNU nroff. Admittedly, this is pointless and eccentric, but it doesn't seem to have been done before. I have failed to do so.

I'm pretty sure that whoever succeeds in writing a no-macro nroff input language quine will need to define strings, or macros or "boxes". To do that you need to write requests like:

.as s "just assigned this to string s
.de xxx
.nop "\*s"
..
.xxx

That is, every request in nroff input has a '.' at the start of the line.

Since quines just output their source code (without cheating), the output probably has to have '.' as the first character of several output lines.

How on earth do you get GNU nroff to output a '.' character at the start of a line? No amount of indirection or escaping can do it, as far as I can tell. Is there some hidden request that outputs a '.' at the start of a line?

I'm using recently synced Arch Linux, which has Groff 1.22.3 installed.

3

From mdoc(7)

The special meaning of a punctuation character may be escaped with the string ‘\&’

So:

\&.

However this might be tricky in combination with subsequent lines as things like

\&.
\&.as s "nron, nroff--very good, again!

Run together (and produces a whole bunch of blank lines)

$ nroff blah | head -2
.  .as s "nron, nroff‐‐very good, again!

Though you can fix that by adding a blank line, or possibly using other macros

\&.

\&.as s "nron, nroff--very good, again!

Though I don't know how that will affect the needs of quine...

  • nice Karate Kid reference. Since I think of "nroff" as "N roff", I would never have made that joke, whose creation depends on seeing it as "NR off" – Bruce Ediger Apr 21 '17 at 14:53
1

You can set up a translation with .tr which takes pairs of characters to translate from-to. Eg to translate # to .:

nroff <<\!
.tr #.
###abc...
!

produces

...abc...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.