2013-08-08

webfind: How many programming languages can you speak ... at the same time?

When I wrote the following code which compiles and/or executes in 10 different programming languages (C, C++, Perl, TeX, LaTeX, PostScript, sh, bash, zsh and Prolog) and prints a different message in each of them, I think it was cool.

%:/*:if 0;"true" +s ||true<</;#|+q|*/include<stdio.h>/*\_/
{\if(%)}newpath/Times-Roman findfont 20 scalefont setfont(
%%)pop 72 72 moveto(Just another PostScript hacker,)show((
t)}. t:-write('Just another Prolog hacker,'),nl,halt. :-t.
:-initialization(t). end_of_file. %)pop pop showpage(-: */
int main(){return 0&printf("Just another C%s hacker,\n",1%
sizeof'2'*2+"++");}/*\fi}\csname @gobble\endcsname{\egroup
\let\LaTeX\TeX\ifx}\if00\documentclass{article}\begin{doc%
ument}\fi Just another \LaTeX\ hacker,\end{document}|if 0;
/(J.*)\$sh(.*)"/,print"$1Perl$2$/"if$_.=q # hack the lang!
/
sh=sh;test $BASH_VERSION &&sh=bash;test $POSIXLY_CORRECT&&
sh=sh;test  $ZSH_VERSION && sh=zsh;awk 'BEGIN{x="%c[A%c[K"
printf(x,27,27)}';echo "Just another $sh hacker," #)pop%*/

But now I know that the source of this is the the coolest ever (poly.html). I could make it work in 22 languages without changing the original file. Now, that's a feat, congratulations to the author! Good luck for the autodetect feature of your smart text editor to figure out the highlighting. The name of some languages is not explicitly mentioned in the file. Can you find them?

There is another impressive one polyglot with 8 languages: COBOL, Pascal, Fortran, C, PostScript, sh, DOS .com file, Perl.

There is another multilingual program I wrote earlier with 3 languages of: Haskell, Prolog, Perl and Python.

1 comment:

dLux said...

Mentioned in the code:

1, zsh
2, bash
3, sh
4, ruby
5, perl
6, tcl
7, Makefile
8, C++ (trigraphs enabled)
9, C++ (disabled)
10, C89 (trigraph enabled)
11, C89 (trigraph disabled)
12, C99 (trigraph enabled)
13, C99 (trigraph disabled)
14, Haskell
15, python
16, html
17, javascript
18, perl6

Not mentioned:

19, brainfuck
20, whitespace