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:
(list x (list (quote quote) 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:
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.
Here is (hopefully) the definitive page. You can check out the plain quine section, the self-reproduction variations section, and bibliography. If you've visited before, browse the what's new section. Take a look at the want list of languages I'm specifically looking for. Finally, you can browse a list of links.
6/21/99 New Languages: ABC, J, Haskell, Oberon. I've created an other
section for stuff that doesn't fit anywhere
else. This page now mirrored on grex.cyberspace.org
--support Not-for-profit net access & free shells. Also got rid of those nasty gifs and replaced them with nice PNG's
3/1/99 New Languages: RPL, ML, snack, inform. A couple of new palindromes in C, and as
usual, several miscellaneous entries. Linked to my (very small) polyglot page.
2/20/99 New Languages: APL, CAML, dBASE, lua, prolog, Smalltalk. A bunch of new iterating
quines. Sorry it's taken so long to put up all the new code everyone has given me.
12/27/98 New languages: Forth, Rexx, Scheme, Logo, Modula-2, TSE. New variation:
object-printing programs. Linked to IOCCC and GEB FAQ. A ton of new code.
12/23/98 Added another Intercal program, and did some minor fixes.
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
Included in these pages are some minor variations (.sigs, backwards printing programs, palindromes) which may at some point be given their own categories.
HP 48 RPL
Quine Generating Programs
Kimian Self Reproduction
Object Printing Programs
Cheats (right now these are in the language entries. They'll soon have their own category)
Anything you have...
I am especially looking for the major classic (or infamous) languages: COBOL (I'll freely withhold the name of the programmer if they wish ;) ), Jovial, PL/I, SIMULA, Teco, etc.
I should probably point you to my submissions page. Also, if you wrote one of these programs and are angry that I 'stole' it see my copyright page.
The Free Compilers list
indexes compilers, interpreters, and language-related tools available free and in source on the Internet. You can download
it from here.
The Language List
is a historically-oriented list of over 2300 languages which also includes pointers to sources. You can download or search it from here.
You can also use anonymous FTP from rtfm.mit.edu in the `/usenet/comp.lang.misc' directory to obtain either of these lists.
The Jargon File
A collection of Internet slang, folklore, and history. One of the most fascinating documents I have ever seen. Read it. Buy the book too.
The Beer List
List of implementations of a program to print out the entire lyrics of "99 Bottles Of Beer On The Wall" in different programming languages. I think of it and the Hello World page as a wish list. Someday this collection will be that big!
The "Hello, World" Page
Like the above, but for "Hello, World". Better organized too.
The Retrocomputing Museum
A great resource of old, legendary computing programs compiled by the editor of the Jargon File. Everything from APL written by Ken Thompson to Wumpus. I also stole part of his links section ;)
The IOCCC Headquarters
Short for "International Obfuscated C Code Contest" this is a wonderful rescource of really, really ugly code. Several entries have been quines or variations thereof.
alt.fan.hofstadter and GEB FAQ
Lots of neat stuff here. Self-reference galore.
The Search for Self-Documenting Code
A paper on how to write quines. Well written. I have another written by Terry Reedy I
need to put up sometime.
The Polyglot List
Compiled by yours truly, the several multiple language programs I have.
Yahoo! list of quine pages
posted on 2006-04-06 13:58 汪杰
阅读(270) 评论(6) 编辑 收藏 引用