11
\$\begingroup\$

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.
\$\endgroup\$
4
  • \$\begingroup\$ Why the 'maximum level of warning'? That seems rather harsh. \$\endgroup\$
    – marinus
    Commented Dec 30, 2013 at 21:10
  • \$\begingroup\$ I think this is sufficiently separate from those. \$\endgroup\$
    – Timtech
    Commented Dec 31, 2013 at 0:04
  • \$\begingroup\$ 1) 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. \$\endgroup\$
    – J B
    Commented Dec 31, 2013 at 21:11
  • \$\begingroup\$ Then there is this: codegolf.stackexchange.com/questions/4481/… \$\endgroup\$ Commented Jun 1, 2015 at 23:30

5 Answers 5

11
\$\begingroup\$

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
\$\endgroup\$
1
  • \$\begingroup\$ This generates warnings when run with perl -w, and doesn't compile at all with -Mstrict. \$\endgroup\$ Commented Dec 30, 2013 at 22:04
2
\$\begingroup\$

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
\$\endgroup\$
2
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ One could possibly argue this is invalid because the language name is Brainfuck and not BF. \$\endgroup\$
    – user344
    Commented Dec 30, 2013 at 22:28
  • \$\begingroup\$ @nyuszika7h It's commonly abbreviated that way. google.com/search?q=BF+programming \$\endgroup\$
    – Tyzoid
    Commented Dec 30, 2013 at 22:54
  • \$\begingroup\$ True, I don't want to be the one deciding this, but it wasn't specified so... \$\endgroup\$
    – user344
    Commented Dec 31, 2013 at 11:00
  • \$\begingroup\$ 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. \$\endgroup\$
    – minseong
    Commented Jun 1, 2015 at 10:48
1
\$\begingroup\$

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.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Careful! The first < will make your BrainF*ck program crash! \$\endgroup\$
    – Tyzoid
    Commented Dec 31, 2013 at 0:13
  • \$\begingroup\$ Yea, invalid... \$\endgroup\$
    – Timtech
    Commented Dec 31, 2013 at 0:46
  • \$\begingroup\$ @Tyzoid Oops, didn't notice :-P fixed \$\endgroup\$
    – Doorknob
    Commented Dec 31, 2013 at 1:34
  • \$\begingroup\$ @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. \$\endgroup\$
    – Tyzoid
    Commented Dec 31, 2013 at 3:01
  • \$\begingroup\$ @Tyzoid I mentioned that - "Make sure your BF interpreter supports pointer wrapping." \$\endgroup\$
    – Doorknob
    Commented Dec 31, 2013 at 9:44
0
\$\begingroup\$

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")
\$\endgroup\$
2
  • \$\begingroup\$ I don't know about Lua, but they must also have different version numbers and major syntax differences. \$\endgroup\$ Commented Dec 31, 2013 at 1:49
  • \$\begingroup\$ Well the question did not state the majorness of the syntactical differences. After all, C/C++ entries are valid \$\endgroup\$
    – mniip
    Commented Dec 31, 2013 at 1:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.