|Pathologically Eclectic Rubbish Lister|
One of my assistants has been a assigned a homework (*gasp* I used the "H" word- quick --!) in which he deals with quines. A quine is simply a program that prints it own source. Now I say "simply", but coming up with one, even just a short one, is an exercise in itself. As Ken Thompson adeptly points out in Reflections on Trusting Trust(1984), "If you have never done this, I urge you to try it on your own. The discovery of how to do it is a revelation that far surpasses any benefit obtained by being told how to do it." (He also says, "...FORTRAN was the language of choice for the same reason that three-legged races are popular" but that's another story.)
I certainly did find out he was right. In his paper, he gives some unsatisfying examples and suddenly I had to know more...
Thus, I ended up at
Why is this in the maximum font size you ask? Well, that's because you haven't clicked on it yet. I'll wait now while you do that...
Ok. Hi. Welcome back. Now that you've browsed through at least a few quines, you have a general idea of how they work. I'd say the easiest one to understand is
This quine has simply hexidecimalized its source and it prints it out. That's all fine and dandy until you get to
In his attempt to get it to work, it looks like it automatically turned in obfuscation. As you know, our very own camel code makes four camels out one harmless looking camel. This is not exactly a quine, but a quine may also do impressive stuff with its output. The general method to use is 'initially store the program in a string for later printing' (after you use that same code). It even looks like an eval or two may come in handy for these jokers.
Believe it or not, quines, which seem to have a chicken-egg relationship, are useful in the making of compilers since the compiler needs to read sequences of the code it was written in. The C compiler was written in C (refer to Thompson Presentation). Thompson elaborates by describing how bugs could be written into compilers to create potentially untraceable hacks for security breachs (the topic of his presentation).
AgentM Systems nor Nasca Enterprises nor Bone::Easy nor Macperl is responsible for the comments made by AgentM. Remember, you can build any logical system with NOR.