Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Hello World in four languages... at the same time

by AlexL (Sexton)
on Feb 10, 2003 at 06:44 UTC ( #234034=obfuscated: print w/ replies, xml ) Need Help??

Here's a multiple-language program, or polyglot, that prints out the well-known phrase. It can be run in Perl, C (with one compiler warning), Tcl, and REBOL.
#include <stdlib.h> #include <stdio.h> #define p \ <<END set // [if 0 { ; int main() { /* }}]; puts "Hello world from Tcl!" if 0 { { */ printf("Hello world from C!\n"); return 0; } /* END ; print("Hello world from Perl!\n"); <<quit } exit REBOL [] print "Hello world from REBOL!" quit ;#*/
edit: removed an unnecessary #define, a fragment from an earlier version of the code. It was actually a somewhat cunning way to obfuscate the code, but this code isn't strictly designed just to frustrate the reader.

another edit: The "fix" broke it. It really does work now.

Comment on Hello World in four languages... at the same time
Download Code
Re: Hello World in four languages... at the same time
by Mr_Person (Hermit) on Feb 10, 2003 at 22:20 UTC
    If you enjoy this sort of thing, there's a really good article by Jérôme Quelin which describes how he wrote a program that is valid on four languages: Perl, C, Befunge, and BrainF*ck. Very interesting read on how to trick the different languages into either working with each others syntax or ignoring parts of the program. http://www.if.insa-lyon.fr/eleves/jquelin/quadri.html
      Broken Link. Does this article still exist ?
        Oh Yeah http://web.archive.org/web/20040603150557/http://www.if.insa-lyon.fr/eleves/jquelin/quadri.html
Re: Hello World in four languages... at the same time
by Anonymous Monk on Jan 03, 2008 at 19:33 UTC
    The quit is unnecessary in the REBOL section - don't know about the others. Cool trick though.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: obfuscated [id://234034]
Approved by Louis_Wu
Front-paged by SparkeyG
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2014-10-25 11:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (143 votes), past polls