Information AboutQuine |
|
In Computing , a quine is a Program (a form of Metaprogram ) 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 (indeed, an empty program is not legal ISO C since it has no main() function, so many compilers will reject it).Quines are named after philosopher Willard Van Orman Quine (1908–2000), 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 A quine exists in any programming language with the ability to output any computable string, as a direct consequence of Kleene's Recursion Theorem . The specific idea of quines first appeared in ''Bratley, Paul and Jean Millo. "Computer Recreations; Self-Reproducing Automata", Software -- Practice & Experience, Vol. 2 (1972). pp. 397-400.'' 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 the University Of Edinburgh lecturer and researcher Hamish Dewar. This program appears below: %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
#include
{ int i; printf(" \""); for (i = 0; s {Link without Title} ; i++) {
if (s {Link without Title} == '\') printf("\\"); else if (s {Link without Title} == '"') printf("\\""); else if (s {Link without Title} == ' ') printf("\n");
else printf("%c", s {Link without Title} );
if (i % 48 == 47) printf("\" \""); } printf("\""); }
const char progdata {Link without Title} =
"we have tried to make the code clear
"able, not concise and obscure as many quines are" ", so that
"lear at the expense of length.
" use the same data structure (called \"progdata\" "
"epresents) and its own
#include void quote(const char "
"ng s and prints the
"on of s as it might appear formatted in C "
{ int i; printf(\" \\"\"); " " for (i = 0; s {Link without Title} ; i++) {
if (s {Link without Title} == '\\" "') printf(\"\\\\\"); else if (" "s {Link without Title} == '\"') printf(\"\\\\"\"); " " else if (s {Link without Title} == '\n') printf(\"\\n\"" ");
"/ else printf(\"%c\", s {Link without Title} ); "
" if (i % 48 == 47) printf(\"\" "\"\n \\"\"); } printf(\"\\"\"); }
"follows is a string representation of the progra" "m code, from
"r quote() function, above), except
"tring _itself_ is coded as two consecutive '@' "
const char progdata {Link without Title} = @@; in" "t main(void)
{ " " int i;
for (i = 0; progdata[i" "]; i++) { if (progdata {Link without Title} == '@' && prog" "data + 1 == '@')
"two '@' signs, so we must print the quoted "
{" "
"/
} else printf(\"%c\","
} " " return 0; } "; int main(void)
{ int i;
for (i = 0; progdata {Link without Title} ; i++) { '@' && PROGDATA[I + 1
{
} else
} return 0; } ; Scheme ((lambda (x) (list x (list (quote quote) x))) (quote (lambda (x) (list x (list (quote quote) x))))) SEE ALSO
FURTHER READING
EXTERNAL LINKS
|
|
|