yo dawg
July 16, 2013 8:02 PM   Subscribe

Quine Relay. A quine is a program that produces its own source code as output. This is what happens when you write a program that outputs the source of a program in another language, that outputs the source of a program in another language, and so on through fifty different languages until you get out the source of the program you started with.
posted by invitapriore (41 comments total) 35 users marked this as a favorite
 
Oh, and if you do nothing else, do check out the source to QR.rb.
posted by invitapriore at 8:03 PM on July 16, 2013 [5 favorites]


This is insane.
posted by alms at 8:07 PM on July 16, 2013 [4 favorites]


I very much want to do that, but I also want to see what the source in the other languages looks like. Without having to run through the chain myself.

Sorry. Had a bad morning trying to get Ruby to bloody well install. Screw you, OpenSSL dependencies..
posted by Jimbob at 8:08 PM on July 16, 2013


Oh man and it does them alphabetically. How even...?
posted by Jimbob at 8:09 PM on July 16, 2013


Totally agree Jimbob. In particular, I really want to see a real INTERCAL program, but who wants an INTERCAL compiler around, in case it becomes sentient? That thing is dangerous.

Is the output available anywhere?
posted by Llama-Lime at 8:10 PM on July 16, 2013 [2 favorites]


Some of the intermediate files are available here!
posted by invitapriore at 8:12 PM on July 16, 2013 [4 favorites]


Nice title.
posted by etc. at 8:17 PM on July 16, 2013 [3 favorites]


ATAGGATAGATCGCCCCGGCCGGTGATGCCAGTGATCGCAGTGCATCGATGCATCGCTGATACGTCAGCTGCATGCATGCTCGATGCATGCATCAGTACGATCGCATGCATGCATGCTGCATGC....(3x10^9 bases ommitted)....GGATCACACGCAGAGTTATATGGACGCTGATCGACTACGATCGTACGCTAGCTGAC.
posted by lalochezia at 8:19 PM on July 16, 2013 [9 favorites]


The programmer who wrote this had to defeat the devil in an epic code-a-thon to win the magic Model M keyboard that makes this kind of coding possible. Of this much I'm certain.
posted by mullingitover at 8:21 PM on July 16, 2013 [9 favorites]


It's hard to understand how someone could do this and not include APL.
posted by alms at 8:24 PM on July 16, 2013 [4 favorites]


I know it's a small thing in Ruby, but check out QR.rb and boggle that for all the quine complexity, it's stylized as well. I really want to spool up a guest Ubuntu 13.04 VM and see.
posted by Kyol at 8:31 PM on July 16, 2013


I ran the Go stage through the gofmt pretty printer. Happy to help.
posted by SemiSophos at 8:34 PM on July 16, 2013 [1 favorite]


Dude everything in reality is a quine because everything is the mirror of selfsame creation. That's literally what forever is.
posted by Teakettle at 8:36 PM on July 16, 2013 [1 favorite]


Dude everything in reality is a quine because everything is the mirror of selfsame creation. That's literally what forever is.

Dude...
posted by mullingitover at 8:39 PM on July 16, 2013 [1 favorite]


Holy hell.... they're using Verilog to generate the source in Whitespace. This....shouldn't be possible...
posted by schmod at 8:43 PM on July 16, 2013


It's hard to understand how someone could do this and not include APL.

Lack of APL keyboard. But hey, intercal!
posted by ish__ at 8:44 PM on July 16, 2013


Call me when he includes Malbolge.
posted by double block and bleed at 8:44 PM on July 16, 2013


It's midnight and I have a lot to do tomorrow but I can't go to sleep without seeing if this actually works. Be back in a bit.
posted by double block and bleed at 8:56 PM on July 16, 2013 [1 favorite]


Amazing.
posted by equalpants at 8:58 PM on July 16, 2013


It works!

It took 20 minutes to install the dependencies (repo was slow) and less than a minute to run through all of the languages on my machine running 64-bit Kubuntu 13.04:

steve@bender4:~/temp/quine-relay(master=)$ make

#####################
## Ruby -> Scala ##
#####################

ruby QR.rb > QR.scala

(Lots more)

####################
## REXX -> Ruby ##
####################

rexx ./QR.rexx > QR2.rb

#############
## CHECK ##
#############

diff QR.rb QR2.rb
steve@bender4:~/temp/quine-relay(master %=)$


All of the intermediary programs that I looked at are complete line noise.

Boggle
posted by double block and bleed at 9:41 PM on July 16, 2013 [2 favorites]


I'm going to ask the stupid question that's bothered me since I read "Gödel, Escher, Bach": How do you correctly pronounce "quine"?

Also, this is awesome.
posted by Joakim Ziegler at 10:13 PM on July 16, 2013


This is superb in so many ways.

Browsing through the intermediate files it looks like the most readable one of the lot is the INTERCAL, for certain values of readable.
posted by motty at 10:13 PM on July 16, 2013


I by no means intend to put any of this work down, since it's really phenomenal (I'm genuinely floored by this). However, after looking at all of the code, it's basically print statements in each respective language (with some of them doing a very basic unpacking of a hard-coded string). The big giveaway was Verilog for me, since you can only realistically use the sequential simulation code bits -- that is, there was no way it would use concurrent hardware emulation to generate the next program.

Of course, how the programmer actually got this to loop is beyond me, but I do see how a single chain of multiple languages is possible.
posted by spiderskull at 10:32 PM on July 16, 2013


Interesting discussion of quines from Johannes Loetzsch here, though it doesn't mention quine relays.

It is, I suspect, and as spiderskull asserts, in each language, essentially just a big print statement plus a bunch of escaping of some string in order to work in the next language (without screwing up any of the 48 other languages) but it has to be cleverer than just that, because it is still a quine and does loop back on itself - so each one must still emit itself, in encoded form, as well as everything else.

Writing some Python to emit some Perl to emit some C to emit some Haskell, say, is obviously trivial compared to making the Haskell then emit the original Python.

However, if you first write a Python quine, a Perl quine, a C quine and a Haskell quine, then modify each of them such that they have a payload of all the others as well as themselves and work in a circle, then I think you can look at extending that to arbitrary languages in which you can also write a quine.

So the superlatively clever bit here is 50 quines in 50 languages. What an achievement.

I can't write a quine in any of them.
posted by motty at 10:54 PM on July 16, 2013


How do you correctly pronounce "quine"?

Kwine. (It's named for the philosopher, whose name is pronounced this way, so I assume the programming thing is pronounced the same.)
posted by LobsterMitten at 11:08 PM on July 16, 2013 [1 favorite]


And in case it was the end of the word causing the confusion, it rhymes with 'pine'.
posted by LobsterMitten at 11:09 PM on July 16, 2013


Galactic Council probes are uncloaking as we speak, hearing of this achievement.
posted by benzenedream at 11:19 PM on July 16, 2013 [1 favorite]


Ok ok so I just wrote my first quine, in Python, but it doesn't half make it easier when you've just been looking at a whole bunch of other quines in different languages plus reading discussion of them.
posted by motty at 11:28 PM on July 16, 2013


GCATCGATGCATCGCTGATACGTCAGCTGCATGCATGCTCGATGCATGCATCAGTACGATCGCATGCATGCATGCTGCATGC

It takes billions of iterations and trillions of years of CPU time before you can get that human DNA to take part in a Quine relay.
posted by ambrosen at 1:15 AM on July 17, 2013 [1 favorite]


the QR.m stage is a bit of a cheat. I mean, yes, it's legal Objective C, but it's in the subset of that language that is identical to plain C.

grumble grumble
posted by russm at 3:42 AM on July 17, 2013


Odd that it does ALgol68 and not Algol. Maybe he didn't know they were actually different languages.
posted by Obscure Reference at 4:56 AM on July 17, 2013


I mean, yes, it's legal Objective C, but it's in the subset of that language that is identical to plain C.

...as opposed to the superset of the language that looks like line noise even for sensible programs?
posted by Jimbob at 5:03 AM on July 17, 2013 [2 favorites]


I was gonna ask if it could compile on LosethOS - but it's now TempleOS. On the one hand, it's optimized for virtualization now, while keeping the really fun ring-0 write-to-the-metal features... on the other, blatant racism. I mean pure antebellum BS. I don't even want to link to the new site.
posted by Slap*Happy at 5:06 AM on July 17, 2013


Okay line noise was a bit rude. Closer to a cat walking across a keyboard, stomping on the -@+[ keys.
posted by Jimbob at 5:07 AM on July 17, 2013 [1 favorite]


I mean pure antebellum BS. I don't even want to link to the new site.

Oh wow. He's cracked in a very sad way.
posted by Jimbob at 5:11 AM on July 17, 2013


> LosethOS - but it's now TempleOS

(Metafilter's own) (previously)
posted by ardgedee at 5:20 AM on July 17, 2013 [1 favorite]


pure antebellum BS

I agree that racism is unacceptable, but it's worth noting that the programmer in question is schizophrenic. To whatever extent his writings are expressions of actual racist feelings (and not just word salad), I wouldn't be too hasty to draw parallels with garden-variety ignorant-redneck racism.

I don't condone it, but neither would I condemn him as easily as I would a mentally healthy person.

At any rate, this is utterly amazing work.
posted by escape from the potato planet at 11:37 AM on July 17, 2013 [1 favorite]


Okay line noise was a bit rude. Closer to a cat walking across a keyboard, stomping on the -@+[ keys.

surely if you're going to bag obj-c about something it'd be the excessive verbosity rather than the specific choice of punctuation characters.
posted by russm at 12:07 AM on July 18, 2013


Been unable to stop thinking about this for days, so fwiw, here's how I think you can approach figuring out how this was done, which is basically by doing it, though obviously not going quite as bezerk nor being nearly so clever as the OP.

Step 1 - Write a quine in each language you want to write a relay in.

My First Quines: Python, Perl.

Step 2 - Choose a starting language and merge the other quine(s) into it, modifying them as appropriate or necessary.

My First Quine Relay: Python-Perl.

This involved a lot of tearing my hair out trying to figure out the extremely fine details of string substitution and newline handling in each language. By which I mean Perl - in this case the Python hardly needed any modifying at all other than adding in the Perl bit, but the Perl needed some surgery to cope with emitting the original Python properly. It looks like the quines in the OP use more sophisticated encoding techniques which I'm pretty sure is a good way of avoiding these problems.

Step 3 - For each new language, write a quine in it and merge it in.

The quines in the OP are far cleverer than these - writing quines in some of those languages is an impressive achievement all by itself - but by far the cleverest bit is the cute ASCII art of the Ruby code. Is that itself encoded in the original, carted around all fifty languages and then used by the Ruby-emitter to format the Ruby? It must be, mustn't it?

Looking at the REXX (which emits the Ruby, and has the ASCII art in it already), and then the R (which emits the REXX and has no visible (to me) sign of the ASCII art), it's kind of spooky.
posted by motty at 8:31 PM on July 19, 2013


Here's an earlier version of the 50 quine OP, back when it was only 10 languages (text is Japanese, but the Ruby isn't).

Found via this page with a completely delightful quine in Matlab.

I'm the only one still here, aren't I.
posted by motty at 9:34 PM on July 21, 2013 [1 favorite]


no
posted by russm at 11:24 PM on July 25, 2013


« Older Dear Mr. Watterson   |   2,800 miles in 62 days. Newer »


This thread has been archived and is closed to new comments