kids encyclopedia robot

Quine facts for kids

Kids Encyclopedia Facts

A quine is a special kind of computer program. It doesn't need any information from you, but it can print out its own exact source code! These cool programs are named after a smart thinker named Willard Van Orman Quine.

Quine's Tricky Puzzles

Quine was very interested in a puzzle called the "liar paradox." This is the famous sentence: "This statement is false." Think about it: if the statement is true, then it must be false, which is a problem! And if it's false, then it must be true, which is also a problem! It can't be either true or false.

This kind of puzzle, where something refers to itself, shows up in many places. It's called "self-referential." For example, the liar paradox starts with "this statement," which points right back to itself.

Many people thought you could just ignore these self-referential puzzles. But Quine realized that if you ignored them, you'd also have to ignore quotation. Quotation is when you put words in quote marks, like "hello." When you say "hello," you're talking about greeting someone. But when you quote "hello," you're talking about the word "hello" itself, not its meaning.

Quine came up with his own tricky puzzle that wasn't self-referential in the same way. It was: '"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.' This sentence talks about what happens when you write a phrase in quotes and then write the phrase again without quotes. It's a bit like a more complex version of the liar paradox!

How Quines Work in Programs

Most programming languages also have a way to "quote" things. This means you can put quotes around some code, and the computer won't run that code. Instead, it just stores it as a string (which is like a sequence of letters or characters).

The clever trick to writing a quine is to make a string that has a "hole" in it. Then, the program outputs that string, but it fills the "hole" with its own "quoted" version.

For example, in a language called Python, there's a function called repr that "quotes" a string. The % symbol helps fill in a "hole" marked as %s in the string.

def quine():
    "Returns its own source code"
    s = 'def quine():\n    "Returns its own source code"\n    s = %s\n    return s %% repr(s)\n'
    return s % repr(s)

In JavaScript, you can use JSON.stringify to "quote" an array (which is a list of items). The "hole" can be the space between two parts of the array.

function quine() {
    var a = ["function quine() {\n    var a = ", ";\n    return a[0] + JSON.stringify(a) + a[1];\n}"];
    return a[0] + JSON.stringify(a) + a[1];
}

In CoffeeScript, you can write a quine that looks a lot like Quine's original paradox. It's a phrase followed by its own "quoted" version.

quine = -> ((t) -> t + JSON.stringify t) "quine = -> ((t) -> t + JSON.stringify t) "

See also

Kids robot.svg In Spanish: Quine para niños

  • Quine (computing)
kids search engine
Quine Facts for Kids. Kiddle Encyclopedia.