Post Archive

› September 15, 2004

A quine is a quine is a ...

  • Reported by liorean

Oh no! It's that deranged geek again, with his ridiculous self replicating programs!

Well, I thought a followup would be nice. Quines are normally not useful, but are fun challenges that hone your programming skills. Creating quines isn't really that hard once you have found the secret "what", but if you want to vary the "how" of them you have to start thinking.

The "what" of quines

...lies in understanding their structure. They basically contain two parts, a template and a factory part.

The factory part takes a template and returns the reconstructed template in some way combined with the evaluation of the template. These factories could essentially generate anything, all dependent on the template they are given. However, for the program to be a quine, the template must be such that it generates the factory. The only exception to this are the delimiterless literals that when converted to strings generate their own source code, such as number literals, boolean literals, null literals, undefined literals and regex literals. In a way, you could say the unifying thing about these is that they are the cases where the template and the factory cooincide. That's why I chose as the first rule of the contest that the output must be a string. Strings are compound literals (i.e. they contain delimiters that are not included when cast to strings).

The template must as mentioned be of the nature that it evaluates to the factory. This might be more or less simple, as the evaluation process is defined in the factory. At the simplest level the factory simply appends the delimiters to each side of the template and then append the template itself to that.

On another note

Microsoftian Eric Lippert noted the contest after it ended and says I'm totally bummed that I didn't hear about this until it was over. I was actually hoping for Sjoerd Visscher and the Lambda the Ultimate crowd to notice it, but they didn't. Oh well, Eric's post JScript, DNA, and Mad Cow Disease has some interesting discussion about the nature of quines, similar to the thoughts about templates and factories that I have presented here. As a medical student I just can't avoid being interested in his analogues with cellular biology, though I think cheating quines would more fit the virion metaphor than the prion metaphor. This one is worth a read, especially the two challenges he presents at the end of it.

Comments

1. September 16, 2004 02:37 PM

Quote this comment

Sjoerd Visscher Posted…

I'm sorry I missed it too. Nice contest!