"preceded by itself in quotes." preceded by itself in quotes.
Named after Willard van Orman Quine, by Douglas Hofstadter.
"Is a statement without a subject" is a statement without a subject.
"Would be a silly name to give a child" would be a silly name to give a child.
And furthermore.
"gives resc food for thought" gives resc food for thought
To manufacture a computer quine, a program which prints its own source code, you might do this:
"is made up of six words" is made up of six words.
Which is much more profound than it seems at first sight, and is a useful first step towards looking at self referential stuff like "this statement cannot be proven". It shows what the "this" is really doing, ie its inserting the reference to the rest of the sentence.
quine, v. To deny resolutely the existence or importance of something significant. - The Philosophical Lexicon (8th edition, 1987). Yes, 'quine' is a verb as well! This eccentric and satirical usage comes from W. V. O. Quine's tendency to deny the existence of things in this way (for example, it has been claimed of his philosophy that it denies the existence of beliefs).
quine, v. To deny resolutely the existence or importance of something significant.
The classic use of this term may be in Daniel Dennett's 'Quining Qualia' (in Consciousness in Contemporary Science, eds. Marcel and Biasch, OUP); a paper where Dennett argues that subjective experience is not 'special' in the ways that other thinkers have presumed (i.e., the ways in which qualia are special).
Most self-reps are self-refs. Most self-refs are not self-reps. Additionally, in computer languages, the word "quine" is almost exclusively used to refer to self-reps, even the ones that work by some mechanism other than quining (quoting themselves).
Most of the English sentences above are self-refs, and the computer examples are self-reps. '"preceded by itself in quotes." preceded by itself in quotes.' is both an English quine and a self-rep, because it actually does thoroughly describe itself.
For the sake of comparing what is and is not a self-rep:
I've revised this node after discovering that 'quine' was originally used to mean self-ref and not self-rep. After changing some words, the points before still stand, but the closing statement that I rather enjoyed writing no longer holds:
In summary: "'is not a quine' is not a quine" is not a quine. And neither is the previous sentence.
int n=103;char*f="int n=%d;char*%c=%c%s%c; main(){printf(%c,205-n,n,34,%c,34,n,n,10);}%c"; main(){printf(f,205-n,n,34,f,34,n,n,10);}
This is not a bi-quine nor a multi-quine, I'm not sure what to call it.
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. (We ignore some variants of BASIC in which a program consisting of a single empty string literal reproduces itself trivially.) 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. Here is another elegant quine in ANSI C:
#define q(k)main(){return!puts(#k"\nq("#k")");} q(#define q(k)main(){return!puts(#k"\nq("#k")");})
Some infamous Obfuscated C Contest entries have been quines that reproduced in exotic ways. There is an amusing Quine Home Page.
--The Jargon File version 4.3.1, ed. ESR, autonoded by rescdsk.
This first example, while a valid quine, is considered "cheating" by those in the know , since it opens itself and simply scans its own source code:
#! /usr/bin/perl -w # This is not really a quine: open (Q, $0); while (<Q>) { print; }
This next example is considered a quine amongst the Perl community, but it still seems like cheating to me, using a syntactic trick of Perl to do it's job. It takes advantage of the fact that Perl will scan the __DATA__ structure before it is even declared:
#! /usr/bin/perl undef $/; $_ = <DATA>; print; print; __DATA__ #! /usr/bin/perl undef $/; $_ = <DATA>; print; print; __DATA__
Here is another example that is a little more fun, courtesy of Blake Mills (Blakem on perlmonks):
#!/usr/bin/perl printme(q{ sub printme { print "#!/usr/bin/perl\n\n"; print "printme(q{$_[0]});\n"; print "$_[0]"; } }); sub printme { print "#!/usr/bin/perl\n\n"; print "printme(q{$_[0]});\n"; print "$_[0]"; }
Now is where it starts getting really interesting. Try and GOLF your own in any language!
A quine, as every good programmer should know, is a program (or sentence) that produces itself when run, without using its own source. They are named after Willard Van Orman Quine, a philosopher who studied self-reference. From HQ9+'s
Q
print "print "print "print "print...
However, you should know:
So let us make a quine, to see what makes it tick. Note that we are going for understanding, rather than conciseness, so if you want large globs of unintelligible code to run there are plenty out there (see the link at the bottom).
The easiest type of quine to do is one that simply loads its own source, and prints that:
int main() { FILE *f = fopen("/path", "r"); char c; while (c = (getc(f))) putchar(c); fclose(f); }
But this is considered cheating by many as it goes against the rule of not using its source. Besides, this does not work on compiled programs.
All proper quines must contain the same code twice: one to execute, and another in a string to print out. This program can print out part of it:
int main() { int a = 0; printf("int a = 0;\n"); }
This looks simple enough, so far. The most difficult task, though, is printing the command that prints - as you can imagine, you would have to print the command that prints the command that prints the command, and so on ad infinitum.
int main() { char *s = "int main(){ char *s = \"int main(){ char *s = \\\"int main(){ char *s......."; printf(s); }
The string s is going to be pretty big, if we keep on going like that way. And even if you could have it infinitely long, it would take ages to download from the Internet. The thing to do here is put the string in itself. By using %s in a string, with the string as its argument, we can encode the string inside itself, giving us a string containing the entire program's code, which we can then merrily printf out.
int main() { char *s = "int main(){char*s=\"%s\"; printf(\"s,s\");}"; printf(s, s); }
If you cannot tell what is going on here, think of the printf statement as:
printf("int main(){ char*s=\"%s\"; printf(\"s, s\"); }", s);
So are we done? Not quite. If you try running the code, it prints the string s fine. However, if you try running the code that that produces, it doesn't quite compile. Oh dear. What's wrong? The generated program, although it looks fine, does not escape the quotes in the string - it uses " instead of \", and the C compiler chokes on it. We cannot escape them, as then the original program would not be correct. Instead, we must print the character (ASCII code 34) with a printf %c, instead of actually quoting it in the string, as well as adding it to the printf statement. This way, the quotes are carried through into the source that the program generates.
int main() { char *s = "int main() { char *s = %c%s%c; printf(s, 34, s, 34); }"; printf(s, 34, s, 34); }
Echo it, compile it, and run it. Then run that, and, if you want, run what that produces as well. Run it as many times as you like, you'll get the same thing. Which means we finally have our quine, yay!
Variants on this method include printing a series of character codes instead of a string, or running exec() on a string to print it out. Some programs manage to produce a quine slightly different from the original. For examples, as well as other eschewed code, see the Obfuscated C Contest.
Now that they look a lot less like blocks of meaningless code now, why don't you try a few others? http://www.nyx.net/~gthompso/quine.htm contains the list.
printable version chaos
Everything2 Help
cooled by Halspal