Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

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
Replies are listed 'Best First'.
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.
      Broken Link. Does this article still exist ?
        Oh Yeah
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?

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
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2015-11-29 15:43 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (751 votes), past polls