Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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

by AlexL (Sexton)
on Feb 10, 2003 at 06:44 UTC ( [id://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.

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. 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
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (2)
As of 2024-04-20 04:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found