I'm not the language you're looking for!

  • Isn't it annoying when you find a piece of code and you don't know what language it was written in? This challenge attempts to somewhat solve this.



    Challenge



    You will have to write a program that when run in two different languages, will output the string:



    This program wasn't written in <language program compiled/interpreted in>, it was built for <other language the program can be run in>!




    • In the output, language names should have official capitalization. eg: CJam, C++


    • Neither program should take any input from the user.


    • When run in both languages, output should be to stdout or equivalent.


    • There should be no output to stderr in either program.


    • You may use comments in either language.


    • Two different versions of the same language count as different languages.




      • If this is done, the program should output the major version number, and if running on two different minor versions, should report the minor version also.


      • You should not use prebuilt version functions (this includes variables that have already been evaluated at runtime).





    Example output:



    Perl and Ruby:




    • Perl: This program wasn't written in Perl, it was built for Ruby!


    • Ruby: This program wasn't written in Ruby, it was built for Perl!




    Python and C:




    • Python: This program wasn't written in Python, it was built for C!


    • C: This program wasn't written in C, it was built for Python!




    Python 2 and Python 3:




    • Python 2: This program wasn't written in Python 2, it was built for Python 3!


    • Python 3: This program wasn't written in Python 3, it was built for Python 2!




    Python 2.4 and Python 2.7:




    • Python 2.4: This program wasn't written in Python 2.4, it was built for Python 2.7!


    • Python 2.7: This program wasn't written in Python 2.7, it was built for Python 2.4!




    This is code golf so the shortest code in bytes wins.


    "Two different versions of the same language count as different languages." So tricking like with C pre and past 99 comments is valid? easy ^^

    Added it, it feels paradoxical but fits to your rules.

    No one's doing a Whitespace/Python polyglot?

    nevermind. Saw the 23 implementation

    Does relying on the program to be run with a certain interpreter count as input? that is, switching on `argv[0]`?

    @cat You should not use prebuilt version functions. looking at `argv[0]` counts as that I guess

    What that thing is for, at all?

    For the fun of the person answering

  • jimmy23013

    jimmy23013 Correct answer

    6 years ago

    Foo/CJam, 70 bytes


    "This program wasn't written in ""Foo"", it was built for ""CJam"\@"!"

    In Foo, as many have found out, it just prints everything in the double quotes, and ignores most other character or does something that doesn't affect the output in most cases. In short, \@ does nothing and the strings are all printed as-is.


    In CJam, \ swaps the top two items, and @ moves the 3rd item to the top, which arrange the strings into the right order. And after the program ends, everything left in the stack is automatically printed.


    And just for the fun of it, there's a similar 75-byte solution for Fission/CJam: `R"This program wasn't written in ""Fission"", it was built for ""CJam"\@'!O`

    Nice. I had `"This program wasn't written in Clip, it was built for CJam!"3{4-_36+e\}/` for Clip/CJam.

    I came into this thread to post a Foo solution, should've realized everybody knows by now how easy it is to write a Foo polyglot.

    Is there a link to the Foo programming language spec?

    How does this work?

    @ErikE Added some explanation.

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM