6 ms·
Quines: self-replicating programs (2005)
- m3kw9 6y agoWhat would be a practical use of this?
- awake 6y agoA computer worm
- xamuel 6y agoNot directly a quine per se, but suppose you want to write a computer program which writes computer programs. And you want all these programs (both the one writing them, and the ones written) to be 100% self-contained, no importing from a util file or anything like that. Then if a util function shall be used in the writing program as well as in the written programs, then it'll need to be "injected" into the written programs in a Quine-like way. 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/src/LevelOmega/standalone/w%5Ew.py https://raw.githubusercontent.com/semitrivial/ions/master/sr... (For the context behind that program, see: https://github.com/semitrivial/IONs https://github.com/semitrivial/IONs)
- gliese1337 6y agoThe 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 6y agoI'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 6y agoSure, except in this case the "source code reader" is also built from the source in question. More analogous, perhaps, to a self-hosting compiler.
- gliese1337 6y agoTrue, but the point is not to produce a direct analogy--merely an existence proof.
- mrastro 6y agoThere might be no practical uses for this but it exemplifies programming as some sort of self-referential Ouroboros-type art. I think it's cool.
- mkj 6y agoIt makes it simple to fulfil copyleft obligations to distribute source. Also helps avoid losing source to old programs - a custom vending machine firmware I know embeds source. 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.
- xamuel 6y agoYou 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()
- identity0 6y agoI mean, obviously. I would say it counts as cheating though. It’s on the same level as opening the source code file and printing it out.
- xamuel 6y agoNo it's not on the same level, it's subtly different. The file could be altered during the brief instant between when you execute the file and when the program loads itself. Or the whole thing could be run from the REPL with no "file" at all.
- identity0 6y agoNot cheating as in “it might not work,” cheating as in “it trivializes the exercise.” The point of making a quine is a programming challenge. If python had a function called “quine()”, I would still call it cheating even if it worked 100% of the time.
- xamuel 6y agoSure, which is why I said "way easier". If you were assigning quine as a python homework exercise, and you wanted an "exec" solution ruled out, you would need to explicitly rule it out in the text of the exercise. >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). :)
- klyrs 6y agoPeople consider this cheating but idk print(open(__file__).read())
- dang 6y agoParticularly 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&query=comments%3E3%20Quine&sort=byDate&type=story https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
- sixstringtheory 6y agolooked 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 6y agoMaybe 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);}
- hasa 6y agoThis could be an evolution of software.
- hans0l074 6y agoI 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.