Quine |
: This is an article about a kind of computer program. For a biography of the logic and philosophy see Willard Van Orman Quine.
In computing, a quine is a computer program (a form of Metaprogramming (programming)) that produces its complete source code as its only output. For amusement, hackers sometimes attempt to develop the shortest possible quine in any given programming language.
Note that programs which take input are not considered quines. This would allow the source code to be fed to the program via keyboard input, opening the source file of the program, and similar mechanisms. Also, a quine which contains no code is ruled out as trivial; in many programming languages executing such a program will output the code (i.e. nothing). Such an empty program once won the worst abuse of the rules prize in the Obfuscated C contest.
Quines are named after philosopher Willard Van Orman Quine, who made an extensive study of indirect self-reference: he coined, among others, the paradox-producing expression, yields falsehood when appended to its own quotation.
=History=
This hackish phenomenon was first described in Bratley, Paul and Jean Millo. Computer Recreations; Self-Reproducing Automata , Software -- Practice & Experience, Vol. 2 (1972). pp. 397-400.
Paul Bratley first became interested in self-reproducing programs after seeing the first known such program written in Atlas Autocode at Edinburgh in the 1960s by Edinburgh University lecturer and researcher Hamish Dewar.
This seminal program has been found and is reproduced here:
%BEGIN !THIS IS A SELF-REPRODUCING PROGRAM %ROUTINESPEC R R PRINT SYMBOL(39) R PRINT SYMBOL(39) NEWLINE %CAPTION %END~ %CAPTION %ENDOFPROGRAM~ %ROUTINE R %PRINTTEXT %BEGIN !THIS IS A SELF-REPRODUCING PROGRAM %ROUTINESPEC R R PRINT SYMBOL(39) R PRINT SYMBOL(39) NEWLINE %CAPTION %END~ %CAPTION %ENDOFPROGRAM~ %ROUTINE R %PRINTTEXT %END %ENDOFPROGRAM
=Examples=
For more examples, see
; C programming language #include char*i= \#include ,n= ,q= ,*p= %s%cchar*i=%c%c%s%c,n= %cn ,q= %c ,*p=%c%c%s%c,*m=%c%c%s%c%c;%s%c ,*m= int main(){return!printf(p,i+1,n,q,*i,i,q,*i,q,n,q,p,q,n,q,m,q,n,m,n);} ;int main(){return!printf(p,i+1,n,q,*i,i,q,*i,q,n,q,p,q,n,q,m,q,n,m,n);}
; Haskell programming language main=putStr$q++show q;q= main=putStr$q++show q;q=
; Python programming language a= a=%r;print a%%a ;print a%a
; Scheme programming language ((lambda (x) (list x (list (quote quote) x))) (quote (lambda (x) (list x (list (quote quote) x)))))
=See also=
=Further reading=
=External links=
|
|