News for hackers. Stuff that matters.
Re:Poly.html - check the source by siong1987 on Monday January 19, 2009 @04:10AM (#440257)
Python, Ruby, Bash, HTML, Javascript tested. Worked.
Re:Poly.html - check the source by zepolen on Monday January 19, 2009 @04:50AM (#440279)
There is even brainfuck and whitespace in there...
Re:Poly.html - check the source by unalone on Monday January 19, 2009 @05:00PM (#440961)
Huh! Somehow I missed whitespace in the source...
Re:Poly.html - check the source by mace on Tuesday January 20, 2009 @03:51AM (#441550)
Presuming you have the languages installed, this script will download and execute it for each language except javascript and brainf*ck.

  #!/bin/sh

  SRC_FN=poly.c
  LHS_FN=poly.lhs
  BIN_FN=`basename -s .c ${SRC_FN}`
  curl -s -o ${SRC_FN} http://mauke.ath.cx/stuff/poly.html
  cp ${SRC_FN} ${LHS_FN}

  runghc ${LHS_FN}
  bash ${SRC_FN}
  zsh ${SRC_FN}
  ksh ${SRC_FN}
  tclsh ${SRC_FN}
  perl ${SRC_FN}
  python ${SRC_FN}
  ruby ${SRC_FN}
  make -f ${SRC_FN}

  gcc -w -o ${BIN_FN} ${SRC_FN} && ./${BIN_FN}
  gcc -o ${BIN_FN} ${SRC_FN} -trigraphs && ./${BIN_FN}
  g++ -w -o ${BIN_FN} ${SRC_FN} && ./${BIN_FN}
  g++ -o ${BIN_FN} ${SRC_FN} -trigraphs && ./${BIN_FN}

  rm ${SRC_FN} ${LHS_FN} ${BIN_FN}
Re:Poly.html - check the source by axod on Monday January 19, 2009 @05:47AM (#440317)
This is older than the sun. But still clever.
Re:Poly.html - check the source by tlrobinson on Monday January 19, 2009 @08:17AM (#440418)
I had never heard of trigraphs before seeing this.

http://en.wikipedia.org/wiki/C_trigraph

I think I'll stay away from them.

Re:Poly.html - check the source by dfox on Monday January 19, 2009 @09:57AM (#440478)
Reasoning behind trigraphs (partially explained in footnote in standard, section 5.2.1.1) is that there is something like "Invariant Code Set" which is subset of ASCII and some characters used by C does not fall into this set (which is obvious since C uses all ASCII characters except @ and $, with $ being valid character for identifiers on some compilers). Real usefulness of this feature is exactly zero, but it provides some insight into process of standardization. Uselessness of this is even more pronounced by fact that there is no trigraph sequence for _, which also does not exist in some encodings (althought for slightly different reasons).

Because almost all encodings that are not somehow compatible with ASCII are obsolete now, trigraphs are obsolete too. But it is certainly interesting thing to know about. And by the way "incompatible with ASCII" means that the characters are there, but look different (¤ vs. $, ¥ vs \, and so on...)

Re:Poly.html - check the source by snorkel on Monday January 19, 2009 @04:34PM (#440930)
...or according to the wikipedia article it was intended to support C code entry on keyboards that don't have characters for [, ], {, }, #, etc. In other words torture.
Re:Poly.html - check the source by kqr2 on Tuesday January 20, 2009 @02:43AM (#441515)
Actually, this was useful on an the Apple II series where you didn't have {} characters on the keyboard and wanted to program in C.
Re:Poly.html - check the source by tjr on Tuesday January 20, 2009 @01:33PM (#442030)
I used some IBM mainframe keyboards that didn't have [] keys (but the computer did have a C compiler installed).
Re:Poly.html - check the source by callahad on Monday January 19, 2009 @11:25AM (#440588)
http://ideology.com.au/polyglot/ is a nice eight-language (Cobol, Pascal, Fortran, C, PostScript, Shell, x86, Perl) polyglot program.

Conveniently, it has a source viewer which will highlight relevant parts of the program's structure for a given language. For instance, the C compiler sees this: http://ideology.com.au/polyglot/c/

Re:Poly.html - check the source by shiro on Monday January 19, 2009 @05:10PM (#440977)
Check out this.

http://shinh.skr.jp/dat_dir/fizzbuzz7.gif

It is a valid GIF image file, but also a valid Fizz Buzz program in Ruby, Perl, Befunge, Z80 machine code, and x86 machine code.

Re:Poly.html - check the source by khafra on Tuesday January 20, 2009 @10:45AM (#441833)
Befunge makes it epic, but it could be polycode for the ages if the picture itself compiled to a FizzBuzz program in Piet (http://www.dangermouse.net/esoteric/piet.html)
Re:Poly.html - check the source by zepolen on Monday January 19, 2009 @04:51AM (#440280)
Now make it valid Malbolge and you win.
Re:Poly.html - check the source by paraschopra on Monday January 19, 2009 @06:56AM (#440371)
Genius!
Re:Poly.html - check the source by zack on Monday January 19, 2009 @12:10PM (#440641)
Can someone please explain why this is clever?
Re:Poly.html - check the source by eli on Monday January 19, 2009 @12:16PM (#440652)
It's a single source file that works in a dozen languages.