Home >> Computers >> Programming >> Metaprogramming >> Quines




Inside computing, the quine occurs as program (a form of metaprogram) that produces its complete source code as its only output. For amusement, hackers sometimes attempt to develop a shortest imaginable quine in any given programming language.

Note that computer software which choose input are non considered quines. This would allow a source code to become fed to a program via keyboard input, opening the source file of the program, & similar mechanisms. Besides, a quine which contains there are no code is ruled out when trivial; inside numerous programing language executing such the program might output the code (we.e. nothing). Such an empty program another time won a "worst abuse of the rules" quality in the Obfuscated C contest.

Quines come known as fallowing philosopher Willard Van Orman Quine, who processed an extensive survey 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 1st described around Bratley, Paul & Jean Millo. "Computer Recreations; Self-Reproducing Automata", Programs -- Practice & Experience, Vol. Deuce (1972). pp. 397-400.

Paul Bratley foremost became concerned around self-reproducing computer software fallowing seeing a number 1 known such program written around Atlas Autocode at Edinburgh in the 1960s by Edinburgh University lecturer and investigator Hamish Dewar.

This germinal program has been observed & is reproduced on this button:

%BEGIN !THIS Occurs as SELF-REPRODUCING PROGRAM %ROUTINESPEC R R PRINT SYMBOL(39) R PRINT SYMBOL(39) NEWLINE %CAPTION %END~ %CAPTION %ENDOFPROGRAM~ %ROUTINE R %PRINTTEXT ' %BEGIN !THIS Occurs as 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 extra examples, watch Wikisource:Quines

; C #include char*i="\\#include",north='\n',letter q='"',*p= "%s%cchar*i=%c%c%s%c,n='%cn',letter q='%c',*p=%c%c%s%c,*m=%c%c%s%c%c;%s%c",*m= "int main()" ;int main()

; Haskell main=putStr$q++show q;q="main=putStr$letter letter q++show q;q="

; Python a='a=%r;print a%%a';print a%a

; Scheme ((lambda (x) (list x (list (quote quote) x))) (quote (lambda (x) (list x (list (quote quote) x)))))

The Quine Page
Examples of self-reproducing programs in various languages, with some extensions, including polyglot quines, iterating quines, and quine generators.

Quines
An essay on quines, programs which produce their own listing as output.

A GNU Make Quine
This is a quine written for "make", specifically the gnu version.


Computers: Programming: Metaprogramming: Source Code Generators






© 2005 GeneralAnswers.org