Slashdot Mirror


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!"

7 of 194 comments (clear)

  1. Code includes preprocessor directives by Sancho · · Score: 4, Interesting

    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...

  2. Multilingual is the norm... by KFury · · Score: 4, Interesting

    ...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 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: .');"> 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 string syntax
    ) - Javascript function syntax
    ; - Javascript instruction 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.

  3. just curious by Permission+Denied · · Score: 5, Interesting
    #define ARGV argv

    Why not just do this instead:

    main (int argc, char *ARGV[])

    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.

  4. This article is a gem. by theolein · · Score: 3, Interesting

    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.

  5. not valid c by Anonymous Coward · · Score: 1, Interesting

    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.

  6. Re:Shouldn't this tell us something? by copyconstructor · · Score: 2, Interesting

    Did you even read the article. I'll challenge you to find languages with much more different syntax from C/Perl than Befunge-98 and Brainfuck!

    Malbolge. See these notes on writing hello, world in malbolge:

    this malbolge program generates:

    HEllO WORld

    it's not perfect - i ignored case to make the problem simpler (completion left as an exercise for the reader - it should be possible).

    when i finally got a decent algorithm worked out (i've been playing around with this for the best part of a month - see below), it took a few hours to generate the program on a 500mhz nt box with 96mb memory (the code was written in lisp - i started with clisp on suse linux and then changed to corman lisp on nt) (more numbers here).

    incidentally, i've come to hate malbolge.


  7. Re:"Polyglot" did that 10 years ago! by egreB · · Score: 3, Interesting

    No. No, no. These people should have been shot. THIS IS NOT NORMAL! Go find a shrink!

    On the other hand, it's really, really cool.. How about a contest? Write a program that does a particular thing (dunno, calculate something (like Pi)), and should be compilable/runnable in a lot of languages. You get points from a jury from how good the program solved the task, times number of languages it is written in. Could be quite fun. (-8