Quine
Properties
- alias
- Quine (computing)
- tags
- Diataxis/Concept
- logseq-entity
- Logseq/Entity/Concept
Quine
Overview
Context
- Quines are usually treated as exploratory or recreational programs rather than production techniques, but they are a sharp way to think about self-reference, interpretation, and fixed points in programming languages.
- The term is associated with Person/Douglas Hofstadter/Book/79/Gödel, Escher, Bach and the broader tradition of indirect self-reference.
- Person/Douglas Hofstadter Quote
The name "quine" was coined by Douglas Hofstadter, in his popular 1979 science book Gödel, Escher, Bach, in honor of philosopher Willard Van Orman Quine (1908-2000), who made an extensive study of indirect self-reference, and in particular for the following paradox-producing expression, known as Quine's paradox:
"Yields falsehood when preceded by its quotation" yields falsehood when preceded by its quotation.
Key Principles
- A proper quine does not read its own source file, fetch hidden input, or otherwise "cheat" by relying on the surrounding filesystem.
- The usual trick is to separate the program into printing logic and a textual representation of the whole program, then arrange for each part to emit the other.
- Languages with strong quoting, reflection, or
evalfacilities can make quines shorter, but the underlying idea is still self-description plus re-emission.
Mechanism
- Most quines keep a string or data structure that contains a printable representation of their own body.
- The runtime prints the surrounding scaffolding, then a quoted or escaped form of that representation, then the remainder of the program.
- In that sense, a quine is a fixed point of the execution environment: running it preserves the program text instead of transforming it into some unrelated result.
Examples
- Quines are common programming puzzles in languages like Lisp, Python, Ruby, JavaScript, C, and shell, with the exact construction shaped by each language's quoting rules.
- They are also a useful bridge between playful code-golf culture and deeper results such as recursion theorems and self-referential constructions.
Misconceptions