Hacker News new | ask | show | jobs
by bediger4000 168 days ago
It should be possible. nroff macro language has looping, string interpolation, functions and if/then/else. That macro language should be turing complete. People have written file-infecting virus malware with it, I believe, which indicate that a quine should be possible. I personally have made several attempts at an nroff quine over the years with no success.

If it's not possible, I'd love to see an explanation, so that task can quite weighing on me.

1 comments

Here is an attempt:

  .de Q
  .nf
  .na
  .pso awk 'BEGIN{bs=sprintf("%c",92); pre=bs"&"} {out=pre; for(i=1;i<=length($0);i++){c=substr($0,i,1); if(c==bs) out=out bs bs; else out=out c} print out}' "\n[.F]"
  .ex
  ..
  .Q
Invoke with:

  nroff -U -Tascii quine.roff | sed -Ez '$ s/\n+$//'
Possibly relies too much on awk + sed. So maybe not A+, but better than nothing.
To be completely honest, I don't think that counts. Shelling out to awk means you're not writing nroff.

It's possible to write quines in pure C or perl or m4 or python, without shelling out to another language.