How long is your (language) snake? Following on from the third order quine challenge, your task is to write an Ouroboros program that uses as many languages as possible.

That is, in language A, write a program pA which outputs program pB in language B. Program pB should output program pC in language C, and so on until eventually a program outputs the original program pA in language A.

No two languages in your loop can be the same or subsets or supersets of each other. None of the programs in the loop may be identical.

The longest chain of languages win. The length of the source code will be the tie-breaker.

Here is an example solution of length 3 given by Ventero.

s='print q&lt;puts %%q{s=%r;print s%%s}&gt;';print s%s


with Python generates this Perl snippet

print q&lt;puts %q{s='print q&lt;puts %%q{s=%r;print s%%s}&gt;';print s%s}&gt;


which generates the following Ruby code

puts %q{s='print q&lt;puts %%q{s=%r;print s%%s}&gt;';print s%s}


which then prints the original Python snippet:

s='print q&lt;puts %%q{s=%r;print s%%s}&gt;';print s%s
Here's a loop of 4 languages:

C -> Bash -> Batch -> Python -> C

C

main(){char *c="echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c";printf(c,34,39,92,34,c,92,34,39,34);}


Bash

echo "echo print 'main(){char *c=\"echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c\";printf(c,34,39,92,34,c,92,34,39,34);}'"


Batch

echo print 'main(){char *c="echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c";printf(c,34,39,92,34,c,92,34,39,34);}'


Python

print 'main(){char *c="echo %cecho print %cmain(){char *c=%c%c%s%c%c;printf(c,34,39,92,34,c,92,34,39,34);}%c%c";printf(c,34,39,92,34,c,92,34,39,34);}'