Error quine
Perhaps the sneakiest example of a self-rep is the following: instead of writing a legal expression in the compiler language, you type one of the compiler's own error messages. When the compiler looks at your "program", the first thing it does is get confused, because your "program" is ungrammatical; hence the compiler prints out an error message. All you need to do is arrange that the one it prints out will be the one you typed in. ~ D. R. Hofstadter[1]
A Kimian self-rep, more often called an error quine, is a type of self-reproducing object where the object is not interpreted successfully by its environment, but the failure of the environment happens to produce copies of the object anyway. Kimian self-reps were identified by Douglas Hofstadter and named after wikipedia:Scott Kim.
How to write an error quine
Writing an error quine is much easier than writing a quine, you follow these steps:
- Run any invalid program.
- Feed the error to the interpreter.
- Repeat step 2 until the error provided and outputted are the same.
Sometimes the program executes correctly, sometimes this process might need to repeat a lot of times (even indefinitely!), but if you're lucky enough, you get an error quine!
Examples
brainfuck (qdb)
unbalanced [.
JavaScript (Node.js)
/path:1
(function (exports, require, module, __filename, __dirname) { /home/runner/.code.tio:1
^
SyntaxError: Invalid regular expression flags
at new Script (vm.js:84:7)
at createScript (vm.js:264:10)
at Object.runInThisContext (vm.js:312:10)
at Module._compile (internal/modules/cjs/loader.js:684:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:732:10)
at Module.load (internal/modules/cjs/loader.js:620:32)
at tryModuleLoad (internal/modules/cjs/loader.js:560:12)
at Function.Module._load (internal/modules/cjs/loader.js:552:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:774:12)
at executeUserCode (internal/bootstrap/node.js:342:17)
The file must be store in a UNIX path (i.e.: starts with /)
Lua
syntax error near 'error'
Nim
/Users/t.nim(1, 46) Error: missing closing ' for character literal
The file must be stored in the Users library under the name "t.nim" on MacOS for this quine to work.
Python
File "file.py", line 1
File "file.py", line 1
^
IndentationError: unexpected indent
Replace file.py with the program file name
External resources
- error quine challenge on codegolf stackexchange.
References
- ↑ D. R. Hofstadter, 1979. Gödel, Escher, Bach: an eternal golden braid. p499-503.