A clojure program to generate polyglot higher-order quines. Tested only on linux. Requires minor configuration.

Ideally, the following languages are available on the host system: c, clojure, haskell, java, perl, python, ruby. By python I mean python 2, not python 3.


Modify src/polyq/runtimes.clj so that the paths to language executables and the polyq source code match your machine.

Open a console, cd into the polyq install directory, issue a lein run command, something along these lines: lein run haskell c java perl ruby

The order and number of languages is up to you. At least one, repetitions are allowed. Spelling matters, use lower case.

A somewhat cryptic string should written to the console. Also, two files should be written (or overwritten):

  • bin/tmp/original.xxxx (for some value of xxxx)
  • bin/run

In our example, the original.xxxx file would be original.hs. It contains a haskell program. The text of that program was echoed to the console.

The bin/run file is a shell script. Mark it executable, then run it with no args.

Per our example, here is what should happen.

The run script runs the haskell program. The output is written to a file; it is a c program. The run script compiles and executes the c program. The output is a java program. It is written to a file, compiled, and executed. Its output is a perl program. The perl program is executed, its output written to a file. It is a ruby program. The ruby program is executed; emits a haskell program. That program should be the same as original.hs. The script runs a diff to check whether that is so.


Quines are fixed points of an execution environment. As such,they are sensistive to language versions and such. For instance the generate python code works for me under python 2.3, but fails under python 3.

I have tested this code only on linux boxes. I imagine this could be gotten to work on a mac, or even windows, but I have not tried.


Polyq was inspired by Dan Piponi's Quine Central. I wanted to understand Dan's article. Haskell, lovely as it is, is not my native language, so I built a clojure version.