Hofstadter, what have you done to me

Sep 05, 2007 00:41

There comes a time in every person's life when he or she must quine. This evening, gentle readers, that bell tolled for me. I was pretty happy with my initial attempt in Python:

qu = '\x22\x22\x22'
def pr(p): print p; print "pr(r%s%s%s)" % (qu,p,qu)
pr(r"""qu = '\x22\x22\x22'
def pr(p): print p; print "pr(r%s%s%s)" % (qu,p,qu)""")

Not very advanced stuff, sure, but it gets the job done (without backticks!).

Here is an attempt to write a quine in Processing. The approach I used there is slightly different from the Python code above; it also draws its own source in the applet window, which is kind of fun. You can see the rigamarole I had to go through in order to cope with Java's (apparent) lack of a multiline quoting structure, along with my desire to keep the code easy to read.

Suggestions and feedback solicited: at this point, I'm just relieved to have finally understood the concept of a quine after all these years.

Links: More information on quines, Python quines written by people more clever than me.

neeeeeeeeeeerrrrrrrrrrrrrd, geb, programming

Previous post Next post
Up