The Quine Page


    One day, several years ago, I came across an article in an old Byte on "self-reproducing programs".  I was a curious lad, and looked to see what the article was about.  It said, "Listing 1 is a C program which duplicates itself.  When the program is run it produces (on the standard output) a file containing an exact copy of its own source code".  I was hooked immediately--these guys must be geniuses!  I copied the article at once, and tried to figure it out, but I didn't know C at the time.  Soon after, I found another article, this one in Creative Computing.  It had listings in BASIC, and I was ecstatic.  I soon realized that anyone could write self-reproducing programs, and made a few in BASIC, Pascal, and Forth.
    Later that year I finally got a PC, and quickly forgot about the programs I had written on my old TI-994/A.  Then, last year, as I was skimming through the Jargon file, I saw an entry I had not noticed before:

:quine: /kwi:n/ /n./ [from the name of the logician Willard van Orman Quine, via Douglas Hofstadter] A program that generates a copy of its own source text as its complete output. Devising the shortest possible quine in some given programming language is a common hackish amusement. Here is one classic quine:

     ((lambda (x)
       (list x (list (quote quote) x)))
      (quote
         (lambda (x)
           (list x (list (quote quote) x)))))
This one works in LISP or Scheme. It's relatively easy to write quines in other languages such as Postscript which readily handle programs as data; much harder (and thus more challenging!) in languages like C which do not. Here is a classic C quine for ASCII machines:
     char*f="char*f=%c%s%c;main()
     {printf(f,34,f,34,10);}%c";
     main(){printf(f,34,f,34,10);}
For excruciatingly exact quinishness, remove the interior line breaks. Some infamous Obfuscated C Contest entries have been quines that reproduced in exotic ways.

    "Wow.  A 'common hackish amusement'.  I've seen the Beer List, and the Hello World page, there must be a Quine Page.  I'll have to look around, that should be pretty neat to see what must be hundreds of quines."
    I was half right.  There were hundreds of quines, just no quine page.  Admittedly, there were a few attempts, but none had more than ten or so.  I had found over fifty by the time I came across any of these pages.


Plain (single language) Quines

    I define a quine as a program which reproduces itself on an output device without inputting its source.  For programs of that nature, see the cheats section.
    Included in these pages are some minor variations (.sigs, backwards printing programs, palindromes) which may at some point be given their own categories.

 ABC
 Ada
 Algol
 APL
 Assembly
 Awk
 BASIC
 BeFunge
 BlooP
 BrainF***
 C
 C++
 Objective CAML
 dBASE
 Emacs Lisp
 False
 Forth
 Fortran
 Haskell
 HP 48 RPL
 Icon
 Inform
 Intercal
 Interpol
 J
 Java
 More Java
 Javascript
 LISP
 Logo
 Lpc
 Lua
 Miranda
 ML
 Modula-2
 MUMPS
 Oberon
 Pascal
 Perl
 More Perl
 Postscript
 POV-Ray
 Prolog
 Python
 Rexx
 Scheme
 SGML
 Smalltalk
 Snack
 SNOBOL 4
 Tcl
 TeX
 TSE
 Unix Shell
 Vi

Variations

Multiple Languages(polyglots)
 Iterating Quines
 Quine Generating Programs
 Kimian Self Reproduction

References

Bratley, Paul and Jean Millo. "Computer Recreations; Self-Reproducing Automata", Software -- Practice & Experience, Vol. 2 (1972). pp. 397-400.

Burger, John, David Brill, and Filip Machi.  "Self-Reproducing programs", Byte.  August 1980. pp. 74-75.

Hay, Louise.  "Self-Reproducing Programs", Creative Computing. July, 1980.  pp. 134-136.

Hofstadter, Douglas R. Godel, Escher, and Bach: an Eternal Golden Braid. Basic Books, Inc. New York, New York. pp. 498-504 (et al.).

Wetherell, Charles. Etudes for Programmers. Prentice-Hall, Inc., Englewood Cliffs, New Jersey. 1978. pp. 34-35.
 



Gary P. Thompson II  <gthompso@nyx.net>