Quines: self-replicating programs (2005)
madore.org
madore.org
2013 https://news.ycombinator.com/item?id=6048761
2014 https://news.ycombinator.com/item?id=7276976
2016 https://news.ycombinator.com/item?id=12492812
2019 https://news.ycombinator.com/item?id=19752317 and https://news.ycombinator.com/item?id=20094866
among many others: https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
char*f="char*f=%c%s%c;main()
{printf(f,34,f,34,10);}%c";
main(){printf(f,34,f,34,10);} x="""def f():
print("x=" + '"'*3 + x + '"'*3)
print("exec(x)")
print("f()")"""
exec(x)
f()>If python had a function called "quine()"...
If we wanted to REALLY trivialize it, just use the blank program (which prints nothing, thus prints itself). :)
print(open(__file__).read())Maybe that's what they meant
They are a matter of taste.
Eval. Reading the source.
These are quines by some narrow technical definitions which skates along the surface, but misses all of the beauty.
Maybe the aren’t cheating. But they aren’t special. They might not be disqualified, but they score — at best — 2/10.
* ...the blurring of the distinction between output and code.
* ...the distinction between name and thing-being-named. (The different "x"'s in my example, within different levels of nested quotes.)
* ...leaky context (local variables defined inside the eval scope ending up outside the eval scope, and vice versa).
Harder quines tend to hide all that behind layers of tedious encoding.
If you're really interested in hard quines, you might be interested in trying to dig up some fully-detailed proofs of Godel's incompleteness theorems. It's the same story there: elegant and beautiful ideas, drowned under mountains of tedious encoding.
As a compromise, one could imagine a quine which works by writing programs to disk and then reading those programs (as opposed to reading itself). This would be kind of silly, since the same data could be written to/read from RAM much easier.
USER> #1=(LAMBDA () (WRITE '#1# :CIRCLE T) NIL)
#<FUNCTION (LAMBDA ()) {540F153B}>
The function, when evaluated, prints its code: USER> (funcall *)
#1=(LAMBDA () (WRITE '#1# :CIRCLE T) NIL)
If you read back the printed string, you have an identical function as the first one. The '#n=' binds a reader label n to the AST that follows, and '#n#' is replaced by the AST bound to n, which means your AST can be a circular data-structure.
I added :circle t so that circular structure are printed readably, and the (write ...) is followed by NIL so that the structure is not printed to the REPL during interactive evaluation.You could also write:
#1=(lambda () (eval '#1#))
When you evaluate the expression you have a #1={function, which, when called, returns a #1#}.Here's an extreme example, a program which writes programs, each of which writes programs, each of which writes programs, ..., each program being fully self-contained: https://raw.githubusercontent.com/semitrivial/ions/master/sr...
(For the context behind that program, see: https://github.com/semitrivial/IONs)
If, however, you can construct a quine, those beliefs are no longer "obvious". If you can write a program that replicates itself, then you can build a machine that replicates itself--and living organisms might well be such machines.
It would be cool if someone made a cargo-quine rust crate that bundled and compressed everything for a --source argument, maybe with "cargo vendor" as an option. Probably not _that_ much extra program size.