Quadrilingual Crazy Programming
mtve writes: "Have you ever seen source code that is valid on four languages: Perl, C,
Befunge,
and BrainF*ck?
During last Perlgolf
season famous Perl hacker Jérôme
Quelin submit such inconceivable masterpiece and now he published expanded explanation
of his solution. Caution: that text can hurt your mental health. Play
Perlgolf!"
I have enough trouble making my code compile in ONE language, 4 at the same time is a bit much
"The United States has no right, no desire, and no intention to impose our form of government on anyone else." - Bush 05
He should seek professional help. Soon. That's right up there with self-mutilation.
It's not enough to bash in heads, you've got to bash in minds. - Captain Hammer
Now this is exactly why I am proud to be a programmer. Screw Picaso and DaVinci, this is what real art is all about.
This presents an interesting dilemma though. What Emacs mode do I use to look at the code??? perl-mode, c-mode, I dunno. Fontifying just complicates it even more.
At any rate, this shit is going up in my cube. If they should this in a frame, I would buy it and hang it in my house.
int func(int a);
func((b += 3, b));
http://www-2.cs.cmu.edu/afs/cs/user/chogan/Web/pol yglot
Cobol, Pascal, Fortran, C, Postscript, shellscript, 8086
The more advanced the technology, the more open it is to primitive attack
The whole purpose behind having so many languages is for different specialized needs. There used to be PASCAL for scientists, FORTRAN for mathematicians, BASIC for hobbyists or new programmers... each server a purpose, and was not made to do anything more.
Nowadays, Perl and PHP are almost identical, Obj C, C, and C++ are very similar, Java bears many similarities to Obj C and C++ as well, and most of the new 'Basic' environments like REALBasic and VisualBasic are near clones as well.
All of today's popular coding environments could be condensed to Java, Objective C, Perl, and some form of BASIC. This point is exemplified nicely by the fact that a bit of code can be done to compile in 4 languages... the syntax is already quite close, having so many minor variants is just messy.
The only polyglot archive i am aware of on the whole internet
Everything2 entry on polyglots
It runs/compiles under 7 languages: ANSI COBOL, ISO Pascal, ANSI Fortran, ANSI C, PostScript, Shell Script, and 8086 machine language!!! Check it out, it rocks.
He uses the fact that # is a comment in Perl VERY frequently to use #defines etc that will allow C to act like Perl. Interesting solution, although I question whether the use of such preprocessor directives REALLY counts as making cross-compatible code. Then again, I nitpick the difference between preprocessor and compiler, so...
Well, I guess that is one way to keep people from saying that your implementation isn't portable enough.
Note that, even though this is standard C, gcc won't compile it, complaining about the lack of a "main" function.
It's hard to be religious when certain people are never incinerated by bolts of lightning.
First off, this guy obviously has much better kung-fu than I do...I've never even heard of BrainFuck or Befunge...but I think he kinda cheated on the last two languages. He just hid the code for Brainfuck and Befunge in perl and C comments, so they wouldn't interfere with each other. Now, the perl/C part is really neat, because he used C #defines to translate various Perl characters into C, so the Perl interpreter and C compiler are reading and understanding the exact same code...that's cool. But the B & B code just gets ignored by the Perl interpreter and C compiler because of comments, so this amounts to writing 3 seperate programs (one in BrainFuck, one in Befunge, and one that's bi in C and Perl) and then putting them all in the same file with intstructions as to which compiler/interpreter reads which part, as opposed to writing one piece of code that's meaningful in all 4 languages. I'd call this bilingual, not quadlingual.
We don't have a state-run media we have a media-run state.
Ironically, the article isn't even valid in one language.
Any sufficiently well-organized community is indistinguishable from Government.
The above comment doesn't make any sense at all. I think that much is clear to everyone.
Yeah, it's great to have a piece of code that compiles for four languages, but what's the point if you're just using pre-processor and compiler tricks to get the compiler to look at a different section of the same file? In this file, if I change the problem-solving logic slightly, I have to change it in several places. What would be truly cool (and incredibly difficult), in my opinion, would be to completely eliminate redundant logic.
Befunge is,
Holy mackerel! I am in love. I've found the object of my dreams.
When it was late at night, and we were all bored, we would try to put together C programs that were illegible but yet would still compile. That was lots of fun, and it had lots of people scratching their heads, all night long.
Are you sure you didn't work for Microsoft?
qslack.com
...on th web, anyhow. All the time we deal with several languages, burying one inside another so they'll make sense as they go through successive levels of parsing.
.');"> For those of you who are counting, that's SIX 'enders' in three syntax languages just to form a simple alert box.
. - English syntax
; - Javascript instruction syntax
For example, every day I write SQL that is buried in PHP libraries which extracts more PHP that in turn has HTML and Javascript in them.
For another example of the crazyness, check this simple example. Now if you look at the source, you'll notice the end part of that A-tag was:
' - Javascript string syntax
) - Javascript function syntax
" - HTML attribute syntax
> - XML (err, HTML, whichever) tag syntax
And that's not even a particularly hairy example. That's just client-side and wetware-side parsing.
Kevin Fox
Uhm.... the virus writer could compile his virus even if all he could get was a Brainfuck compiler?
Nope.... Once it's compiled, it's all CPU instructions anyway...
Tim
Omnia vestra castrorum habetur nobis.
Wow, if I saw that a few years ago, I would've been so scared I would've never touched another programming language again! Slashdot, please think of the children before you post things like that.
Looking for a computer support specialist for your small business? Check out
Really? you didn't hear aboutthe new IE buffer overflow error. It's only exploitable if you send 7-bit source code and then run brainfuck, perl, C, or befunge on the code.
Do you even lift?
These aren't the 'roids you're looking for.
Now if only he could come up with an version that did APL, too.
The correct term is tetralingual, not quadrilingual.
"Quadri" comes from Latin. "Lingual" is from Latin. "Tetra" comes from Greek. In general, a compound will be all-Greek or all-Latin, with the occasional exception such as "homosexual".
Quadrilingual is used in 1,210 pages, whereas tetralingual is used in only 14.
I assume your Game Boy reference alluded to Tetris®. In that case, the existence of Quadra negates any "by default, go with the name of the block game" rule. In other words, you need to lay off the drugs ;-)
Will I retire or break 10K?
When I get into my "programming language learning" mode, when I learn a new procedure in one language, I try to make the same program in at leats 7 others....sure, it sounds lame, but it really sticks in my head..
If you're not a Liberal in your 20's, then you have no heart.If you're still a Liberal in your 30's you have no brain.
Why not just do this instead:
Also, another minor quip: the C program is not valid C in either C89 or C99. It's not valid C89 because it uses '//' for a comment, and it's not valid C99 since it introduces main() without declaring the return type. C89 defaults to int if you don't declare the type (both for functions and variables, which can be fun), whereas this behaviour is undefined in C99. Normally, I don't follow the anal-retentive lingual purists, but I think this situation calls for this.
But yeah, this is pretty cool.
I think Sega gets the honors on that one.
"Someone set us up the bomb!"
OK, so it actualy prints "hello polyglots", but still, all it does is output a fixed string. Quelin's program does an actual computation, admittedly a relatively minor one.
Moreover, all of polyglot's languages are languages that people have actually used to write real code. I'm not saying they are all reasonable languages, but one can at least semi-plausibly claim that they were written to be useful. Befunge and BrainF*ck are both toy languages written expressly to be perverse in some way (Befunge to be uncompilable, and BrainF*ck to be absurdly minimalist.)
That said, I was disappointed at how separate the languages' code blocks were in Quilen's program. C and perl share most of the same code, but there are three completely separate code blocks and the work is mostly in getting each language to ignore the others' code. It's probably the only way it can be done, but it's really a short quadralingual wrapper around three separate programs, one of which is bilingual.
5 languages...I'll bet they forgot to count C++
I sort of think it's things like this that make slashdot so worth reading. These gems of pure geekness. +5 to /.
I discovered BrainFuck by chance two years ago and immediately got lost in two nights of trying to get my first quine to compile in the interactive JavaScript BF interpreter. For some perverse reason it is fun. It brings out the little boy in me who used to build model airplanes out of toothpicks: Little unimportant things that become something when you stick them together. perhaps this would also be a possible real world language for programming Nanobots, whose processors wouldn't yet cope with a P4 strapped to their backs.
Huh?
Of your list only C++ is a language. However one could right an Apache module in C++ that accesses a MySQL database... err wait actually that been done!
--- Nothing To See Here ---
[100% ISO 646 Compliant]
SVM, ERGO MONSTRO.
Don't mind him, he's just a troll...
/. ... I'm starting to recognize the trolls by username.
Gees, maybe I need to stop reading
int func(int a);
func((b += 3, b));
Try to get a website to look the same in every web browser.
That's an impressive feat?
Netscape 4.X = Worst browser ever!
My colleagues at work think *I* am nuts because I refuse to use notepad or Visual Café's builtin-text editor to edit .java source files, preferring instead a much more powerful older DOS-based text editor (TSE). They're gonna suffer a heart attack when they see this.
"Trust me - I know what I'm doing."
- Sledge Hammer
I don't know if there's an official term for it, but I often write a function in one language that writes code for another language - for example, using PHP or Perl to write javascript. I've even gone so far as to use PHP to write a SQL statement which in turn is used to determine what will go in a Javascript function that writes HTML code. The example below is rather pointless, but I have come across real situations where it is beneficial to use that many languages together.
That's three "real" languages and one markup language. And if you think that was crazy, think about this - I just had to write that in HTML in a slashdot posting textbox!
My next goal is to make the javascript write out HTML for parameters in a Java applet. And, the whole PHP page is going to be written by a C program exectuted by a cron job that was set up via a perl script (webmin!) That's eight different languages - perl -> bash (I think) -> C -> PHP -> SQL and Javascript -> HTML -> Java. Sadly, I don't think that's nearly as crazy as the quadrilingual program. I need to learn Brainf*ck.
I really hate signatures, but go to my website.
If you rename the file to quadlang.c or quadlang.cpp, then open it as c/c++. If you rename it to quadland.cgi, open it as perl, and so on. That's assuming you're going to rename it before sending it to any compiler.
Of course, that's just another problem with multiple languages per source file - figuring precisely how to name the file.
:^)
Ryan Fenton
only it was in human to human language......oh wait we have some that can't understand their own language and those languages which are universal like money and the hand/finger gesture of giving someone the bird.
How may languages is that understood in?
A genetic algorithm might be a great way to produce such examples. You may be able to speed it up by having lists of common language commands to use as mutation material.
/. can set the world record......if there is such a record.
Turn it into a screen-saver ala Seti style, and maybe
Table-ized A.I.
I was happy to solve 1840, even though I immediately recognized the language, because it is poorly specified and there is no interpreter. But that was nothing compared with my teammates, who solved 1183 with nothing but the problem and pure reason.
The evaluation of an action as 'practical' . . . depends on what it is that one wishes to practice.
He tries to declare an array with a size returned by a function call. In C, array sizes have to be static (that's why C++ has "new" for arrays). He's writing to illegal locations in memory.
I've been working on truly bilingual code for a few years now. Machine code. That will run on both PPC and x86. Now, if only the damn elf header didn't cause one cpu to reject it, even though the binary is valid...
.EXE headers aren't even close. Oh well.
Same with x86 machine code that is clever enough to determine if it's running inside of linux or windows... even though the code itself is valid, the elf vs.
Why is it that Slashdot's editors can't fix the mistakes in the above and many, many other articles before posting? Either they don't notice the errors (in which case they should be sacked and replaced), or it's that important to post the article a minute earlier (highly unlikely), or somehow the original wording is considered "sacred" and Not To Be Changed (stupid if true). Come on here. Does the error rate on the front page have to be so high?
The only reason I'm not blaming the submitter (mtve) as well is because it's possible English is not his first language (or even his second). If it is, shame on him too. We all deserve better.
(Oh yes, for those clueless enough to say "What errors", I threw in the required changes in bold. Also, isn't one Perlgolf link enough?)
czth
did you come up with by yourself or did you rip it from ioccc?
This is practically art. Just reading this guy's solution was amazing, the way he reasoned about each step, and just the IDEA of it. Absolutely unbelievable.
However, I'd like to see more difficult languages. Has anyone done LISP? Has anyone even ATTEMPTED Haskell or ML?
This would be worth a subscription if there was more of it (not more of the same but more in a similar vein of geekiness). REAL geek news! None of that Kayz crap or friking freshmen case mods with melted plastic and neon bulbs. Let them come and stare in awe as the fail to grok the code because the wasted their lives drilling holes in their PC case.
This just shows what coding Perl will do to you.
"Can't sleep. Clowns will eat me"
check the following page for source code that can be used in many languages...
polyglots list
I wrote a Brainfuck interpreter in PHP a while ago which also includes a short introduction to the language.
By the way, Brainfuck was initially named "Mental Masturbation", but the Author Oliver Müller then stuck to a less offensive name :)
I think a better answer is, if you aren't interested, that's fine, don't bother with it.
Microsoft - Where would you like to go today, Maybe Jail?
-- Begin Code snippit beneath this line ---
-- End Code snippit above this line ---
Try it, it should work. You see, the key to getting it to work for everything out there is to compromise what the program can do.
Fortunately, since the goal was to make the program run in as many languages as possible, I can make the code as minimalistic as possible, too!
By the way, the code I mentioned above is property of myself. This code cannot be used in programs without my expressed permission. Doing so would be a violation of the terms in which I am distributing the above code.
Licensing agreements are available. Contact me for more info.
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
Poster named Damiam, you are in violation of the terms of my license. You are hereby asked to cease and desist from distributing your code, and will be contacted shortly with a cease and desist letter saying the same message.
If you do not pay royalties to me, I shall strip you of all your Karma, and fart in your general direction. :)
By the way, if you claim prior art, this is not true. I came up with this program back in 1984 when I was banging enter on the keyboard of my Commodore Pet computer and realized that I was programming it without my knowledge.
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
News Reporter: So how'd you do it?
Guy: Well, the nanotech was already there. I just wrote a small program in BrainFuck in order to hunt down the virus.
Well, at least censorship would go out the window the same time we cure World Disease.
/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
This is pretty clever, but it's not that cool; I do similar stuff all the time. I have to mix VBScript and JavaScript and then there is the question of getting stuff to work on different browsers. You can easily call each different browser a new language because they never work the same.
According to Microsoft, their "Visual Studio" will do 5 languages at the same time !
Muchas Gracias, Señor Edward Snowden !
Also, for your masochistic programming pleasure, you may be interested in the polyglot list and the quine page.
For even more zany programming fun, check out Esoteric topics in Computer Programming. Oh, and my own pathetic attempt at a similar page, Miscreant Programming Languages.
Nathan's blog
so you want it to have read:
"During last Perlgolf season famous Perl hacker Jerome Quelin submit such inconceivable masterpiece and now he published expanded explanation of his solution"
And that got you a +4 insightful? -1 gibberish more like.
While *this* isn't helpful - as C/perl/brainfuck/etc. are high-level languages - one certainly could (try to) design quadralingual machine code so that all of a sudden there's a BSI-style virus that runs on x86/PPC/m68k etc. Granted it probably wouldn't work *well*, but it'd be interesting to see even bilingual assembler.
=)
-Knots
Anarchy$ dd if=/dev/random of=~/.signature bs=120 count=1
doh...thats what it did read...I stand over-caffined and underslept...sorry, maybe I should apply for an editors job.
Cenam is right, If you don't want people asking questions that don't fit with your opinion, that is facist.
I'm sick and tired of the slashdot party members always saying stupid things like : "If you ask a question which does not fit our opinion, you do not belong here". Have you ever considered that there are always 2 sides to every story?
[the part which is relevant to this story]
I asked a fair and legitimate question, why the hell would you want to code something so that it compiles in 4 languages ?
I speak 3 languages and can programme in 20, yet I see no reason for multilingual coding. Personally, I believe this is a great waste of time which is only reported because Slashdot loves stupid geek tricks.
Perhaps we should get more 'news that matters' instead of stuff that splatters.
This is hardly worth any note, it goes against any notion of efficient coding and practicality. However, it seems that there are those of you who believe they are better qualified to judge programming skill.
I ask you if you can reprogram an operating system, create an internet protocol or even design a successful encryption system. Because then you will be qualified to judge me as an equal, not a slashdot party member.
- Kaos games and encryption systems developer
And what, some might ask, sort a lunatic would want to climb a mountain? Or fly in a heavier-than-air craft? Or fly the atlantic? Or break the speed of sound? Or land on the moon? Why launch the first satellite into space? Why, some might ask, post to Slashdot? Or read trolling posts modded down to zero?
Why do people climb Mount Everest? Go to the North/South Pole?
Too see if they can!
You are right it's not practical, efficient or in any way useful. And a great waste of time. And if anybody tried this at work they should get fired. But it's fun!
In my opinion the amount of fun you are able to have with programming is an indication of your skill in programming. If you don't have fun you may still be good, but you'll never be great. Simply because you'll go for the easiest solution every time. You may be good at programming things that have been done a 1000 times before but when it comes to creative new solutions you'll loose
And it isn't facist to critisize someones opinion (which is what both of you does). Its facism when you prevent the other part from expressing his opinion
- We are the slashdot. Resistance is futile. Prepare to be moderated -
Going to antartica is useful, you can see how much global warming has affected the glaciers. It's a place where my country has the most useful science experiments done.
Wrong. it's not a question of liking what you do to be good at it.
I've worked as a waiter and at a supermarket before, I was great at the job but I didn't like it.
I never stop people from expressing there opionion, and I only meta moderate fairly. However, you aren't being modded down for expressing a point of view in contrast to the opionion of the slashdot herd.
- Kaos games and encryption systems developer
I've climbed several mountains: Mt Victoria, Mt Tongariro to name the famous ones. I've flown in a plane almost every winter to queensland.
I have no need, nor inclination to fly over the atlantic. Here's a clue: what country has the kiwi as a national bird?
All of those are far more important than posting messages on a severely biased website or bothering to read them.
- Kaos games and encryption systems developer