Hasty Briefsbeta

Bilingual

How to Write a Quine

2 days ago
  • The author explains quines using an allegory of a machine that can create copies of itself without introspection.
  • A quine is a program that prints its own source code without using introspection.
  • The construction starts with a program that prints a template, then modifies it to insert a copy of itself at a placeholder.
  • In Python, the quine is built using string slicing and repr() to avoid manual escaping.
  • Alternative approaches include find and replace with reversed placeholders and manual escaping with careful ordering.
  • The same principles apply in JavaScript and Excel, with language-specific techniques to avoid quote escaping.
  • A general recipe involves creating a program template that performs find and replace with its own literal, then inserting the literal into the template.