
Quines: self-replicating programs (2005) - lelf
http://www.madore.org/~david/computers/quine.html
======
dang
Particularly good past quiney things:

2013
[https://news.ycombinator.com/item?id=6048761](https://news.ycombinator.com/item?id=6048761)

2014
[https://news.ycombinator.com/item?id=7276976](https://news.ycombinator.com/item?id=7276976)

2016
[https://news.ycombinator.com/item?id=12492812](https://news.ycombinator.com/item?id=12492812)

2019
[https://news.ycombinator.com/item?id=19752317](https://news.ycombinator.com/item?id=19752317)
and
[https://news.ycombinator.com/item?id=20094866](https://news.ycombinator.com/item?id=20094866)

among many others:
[https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...](https://hn.algolia.com/?dateRange=all&page=0&prefix=true&query=comments%3E3%20Quine&sort=byDate&type=story)

~~~
sixstringtheory
looked through all those to see if Quine Relay was mentioned, it was one of
the earlier submissions. But to add something totally new I didn’t see in any
comments, that developer made another quine that animates a rotating globe in
the terminal:
[https://github.com/knoxknox/qlobe](https://github.com/knoxknox/qlobe)

------
bbotond
Maybe it's because I haven't yet had my morning coffee but I find his first
example overly complicated. A much simpler and immediately obvious one [from
this
article]([http://www.nyx.net/~gthompso/quine.htm](http://www.nyx.net/~gthompso/quine.htm)):

    
    
         char*f="char*f=%c%s%c;main()
         {printf(f,34,f,34,10);}%c";
         main(){printf(f,34,f,34,10);}

------
hans0l074
I watched this video recently:
[https://www.youtube.com/watch?v=6avJHaC3C2U](https://www.youtube.com/watch?v=6avJHaC3C2U)
\- and it's one of the best programming related ones I've seen in recent
times. Really well presented as well - and he talks about various Quines - I
won't spoil it for anyone.

------
xamuel
You can do this way easier if the language has an "exec" function. Here's a
python example:

    
    
      x="""def f():
        print("x=" + '"'*3 + x + '"'*3)
        print("exec(x)")
        print("f()")"""
      exec(x)
      f()

~~~
klyrs
People consider this cheating but idk

    
    
      print(open(__file__).read())

~~~
nuclearnice1
What’s not to know?

~~~
klyrs
... if I agree with the consensus about what constitutes "cheating." For
example the wikipedia page suggests that "eval" is okay but accessing the
filesystem is not -- folks here seem to regard eval as cheating for some
reason that escapes me. These decisions seem arbitrary to me

~~~
nuclearnice1
They are arbitrary.

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.

~~~
xamuel
Beauty is in the eye of the beholder. I actually find eval-based quines MORE
beautiful because they highlight the philosophically interesting aspects of
quines, such as...

* ...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.

~~~
nuclearnice1
Very good points on eval. Can the read() example be similarly redeemed?

~~~
xamuel
Good question, I had to think about it for awhile. I think it would take some
elaborate mental gymnastics to try to redeem the read example. The read
example is sort of like an appeal to a higher-power oracle. It isn't self-
contained; it wouldn't work in the REPL.

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.

------
m3kw9
What would be a practical use of this?

~~~
gliese1337
The existence of quines is a nice proof that biology isn't magic. Consider an
alternate history in which computer science develops before organic chemistry.
Prior to the development of organic chemistry, some common beliefs about life
were, for example, that living matter was fundamentally distinct from
nonliving matter, and life could not arise from non-living components; and
that _obviously_ no mechanism could contain its own description, so the only
way biological reproduction could work is if, say, sperm actually contained
miniature complete organisms, which in turn contained even smaller complete
organisms, in an infinite regress (see
[https://en.wikipedia.org/wiki/Preformationism](https://en.wikipedia.org/wiki/Preformationism)).

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.

~~~
cousin_it
I'm not sure the analogy quite works. The DNA of children is physically copied
from parents, there's no quine-like encoding of DNA contents inside the DNA
itself. In other words, life is more like a cheating quine that's allowed to
say "read my source code from disk and print it" :-)

~~~
c22
Sure, except in this case the "source code reader" is also built from the
source in question. More analogous, perhaps, to a self-hosting compiler.

------
hasa
This could be an evolution of software.

