Just Another Polyglot Hacker!

10

Make a program which prints just another #{LANG} hacker where #{LANG} is the name of the language with which the program is being run.

For example, if I run your program with Bash, I'd expect just another Bash hacker as the output, but when running the same program through C++, I'd expect the output to be just another C++ hacker.

Your program must run in and produce correct output in at least two different languages.


This is in no way a duplicate of the other suggested question, Write a polyglot that prints the language's name; that question asks for a rather short (and in my opinion) uninteresting output, increasing the easiness of writing and number of languages in an answer, and then it assesses them (these polyglots) based on the source's length!

A correct response to this question, however, would produce longer outputs, and thus would have actually been fairly challenging and fun to write and it would be more difficult to add languages to your polyglot. I then assess the polyglots in a natural way; by the number of languages they support!

I think that this will lead to very different answers being submitted on either question, but also different uses for these answers; the programs which will be submitted here are the type of programs which would be flaunted around the internet for their ingenuity and creativity, "look! Here's a guy who can pull off a swaggy polyglot in 4 different languages! They're cool!"

When I asked this question, I thought I'd put a twist on the popular and well known Just Another Perl Hacker competition, but add some creativity and an extra "Wow!" factor; JAPH programs are often sported as signatures in forums etc., and I believe entries here will inspire similar use, unlike entries for the other question.

Also, because this isn't a form of code-golf like the other question, but I'm actually assessing answers on the number of languages they support, I believe we can expect some rather incredible entries, making use of language features and loopholes we never knew existed!


Rules:

  • Two different versions of the same language only count separately if:
    • You print out the version as well as the language name, for each version.
    • You detect which version is running thraough a less trivial method than running a ver() function or similar built-in of your language.
    • The two have different major version numbers.

For example, if you say your program runs in both Python 3.4.1 and 2.7.8, here are the necessary outputs:

Python 3.4.1

just another Python 3.4.1 hacker

Python 2.7.8

just another Python 2.7.8 hacker

If your program doesn't produce the above outputs for each version, then you cannot list the two separate versions as different languages under which your code runs.

  • You may not have any errors on the maximum level of warning in any of the languages.
  • Program must terminate.

Winner:

  • Whoever's (valid) answer supports the most languages. In the case of a tie, the shorter answer (by program byte count) wins.

ike

Posted 2013-12-30T19:53:57.260

Reputation: 1 753

Question was closed 2013-12-31T01:13:10.990

Why the 'maximum level of warning'? That seems rather harsh. – marinus – 2013-12-30T21:10:45.180

I think this is sufficiently separate from those. – Timtech – 2013-12-31T00:04:49.610

>

  • Please don't write your question starting with what's it's almost like, then what to change to make it the question (or, in your case, initial idea, then edit), it's really a pain to read. 2) It's still the same challenge as the question marked as duplicate.
  • < – J B – 2013-12-31T21:11:21.863

    Answers

    11

    C, C++, Perl, Bash – 230

    #include <stdio.h>
    #define c const char*\
    s="just another %s hacker\n"
    //bin/test;printf "$s" Bash;exit
    int main(){c;printf(s,sizeof'a'-1?"C":"C++");}
    /*==;seek DATA,0,0;@a=readline DATA;eval'$'.$a[2];printf $s,"Perl";
    __DATA__*/
    

    This was fun! :-)

    230 chars including a newline at end of file. To run, save as both poly.c and poly.cpp and do:

    $ gcc -Wall -Wextra -pedantic poly.c && ./a.out 
    just another C hacker
    $ g++ -Wall -Wextra -pedantic poly.cpp && ./a.out 
    just another C++ hacker
    $ perl poly.c
    just another Perl hacker
    $ bash poly.c
    just another Bash hacker
    

    Tobia

    Posted 2013-12-30T19:53:57.260

    Reputation: 5 455

    This generates warnings when run with perl -w, and doesn't compile at all with -Mstrict. – Ilmari Karonen – 2013-12-30T22:04:16.030

    2

    ANSI C/C++

    #ifdef __cplusplus
    #    include <iostream>
    #    define LANG "C++"
    #    define PRINT(text) { std::cout << text; }
    #else
    #    include <stdio.h>
    #    define LANG "C"
    #    define PRINT(text) { printf("%s", text); }
    #endif
    
    int main(void) {
        PRINT("just another ");
        PRINT(LANG);
        PRINT(" hacker\n");
    
        return 0;
    }
    

    Compiling and executing:

    $ gcc -ansi -Wall -Wextra -pedantic -o prog-c prog.c
    $ ./prog-c
    just another C hacker
    $ g++ -ansi -Wall -Wextra -pedantic -o prog-cpp prog.c
    $ ./prog-cpp
    just another C++ hacker
    

    nyuszika7h

    Posted 2013-12-30T19:53:57.260

    Reputation: 1 624

    2

    BASH + BrainF*ck + PHP, 269 characters

    #><?="Just another PHP hacker\n";die();?><
    echo Just another BASH hacker #++++++++++[>+++++++>++++++++++++>++++++++++>+++++++++++>+++>+<<<<<<-]>++++.>---.--.+.>>>++.<<---.>.+.<<.>+++++++.---.>+++.>.<<<<<++++[>--<-]>.++++.>>>>.<<+++.-------.++.>-------.<++.>+++++++.>>.
    

    Running the program:

    $ php langs.sh 
    #>Just another PHP hacker
    $ ./2langs.sh
    Just another BASH hacker
    $ bf 2langs.sh
    Just another BF hacker
    

    A bit of stretching the rules with that PHP one, but it seems to work. I can fix it if it doesn't count.

    Tyzoid

    Posted 2013-12-30T19:53:57.260

    Reputation: 692

    Why not just edit the brainfuck program? Then it will be valid and it won't take very much effort to append a longer program in that comment. – theonlygusti – 2015-06-01T10:48:00.837

    One could possibly argue this is invalid because the language name is Brainfuck and not BF. – nyuszika7h – 2013-12-30T22:28:52.823

    @nyuszika7h It's commonly abbreviated that way. https://www.google.com/search?q=BF+programming

    – Tyzoid – 2013-12-30T22:54:17.120

    True, I don't want to be the one deciding this, but it wasn't specified so... – nyuszika7h – 2013-12-31T11:00:30.147

    1

    JavaScript, HTML, BF

    <!--
        // > to fix previous comment delim
        /*
            ++++++++++[>+++++++>++++++++++++
            >++++++++++>+++++++++++>+++>+<<<<<<-]>++++
            .>---.--.+.>>>++.<<---.>.+.<<.>+++++++.---
            .>+++.>.<<<<<++++[>--<-]>.++++.>>>>.<<+++.
            -------.++.>-------.<++.>+++++++.>>.
        */
        alert('Just another JavaScript hacker')
    // --> Just another HTML hacker
    

    Relies on the fact that most JS implementations ignore <!--.

    BF code shamelessly stolen from @Tyzoid, all credit to him :-)

    Make sure your BF interpreter supports pointer wrapping.

    Doorknob

    Posted 2013-12-30T19:53:57.260

    Reputation: 68 138

    1Careful! The first < will make your BrainF*ck program crash! – Tyzoid – 2013-12-31T00:13:10.077

    Yea, invalid... – Timtech – 2013-12-31T00:46:09.480

    @Tyzoid Oops, didn't notice :-P fixed – Doorknob – 2013-12-31T01:34:14.743

    @DoorknobofSnow It's still not fixed. The problem is that BF starts on element zero on the tape, and does not allow a < to move you to element -1. It crashes before it hits your fix. It's the same problem I'm having with my PHP solution. – Tyzoid – 2013-12-31T03:01:11.487

    @Tyzoid I mentioned that - "Make sure your BF interpreter supports pointer wrapping." – Doorknob – 2013-12-31T09:44:39.180

    0

    Lua 5.3/5.2/5.1/5.0/4.0/3.2

    You said as long as I don't use _VERSION it is fine

    print("Just another Lua"..(string and(loadstring"return 0//0"and"5.3"or(_ENV and"5.2"or(string.gmatch and"5.1"or"5.0")))or tremove(next({[{"4.0","3.2"}]=1},nil))).." hacker")
    

    mniip

    Posted 2013-12-30T19:53:57.260

    Reputation: 9 396

    I don't know about Lua, but they must also have different version numbers and major syntax differences. – Juan Sebastian Lozano – 2013-12-31T01:49:51.910

    Well the question did not state the majorness of the syntactical differences. After all, C/C++ entries are valid – mniip – 2013-12-31T01:52:59.033