Write a "hello world" program that can be compiled/interpreted as two different languages simultaneously

-3

0

Rules:

  1. Your program must print "hello world" when executed

  2. Your program must be interpretable or compilable into 2 or more languages

  3. Your program must require no input or arguments

  4. Languages with identical syntax are too easy, and will be shunned. We all know you can write echo hello world in Bash and Batch, so let's make it more interesting.

I'll add my example as an answer.

BLuFeNiX

Posted 2019-08-30T04:03:54.217

Reputation: 95

Question was closed 2019-08-30T04:26:27.893

1

Welcome to Programming Puzzles and Code Golf! I marked your challenge as duplicate of this challenge, which is almost identical with just a different scoring algorithm. Additionally, "identical syntax" is not an observable or objective requirement, and needs to be more clearly defined or removed to make this challenge valid by the rules of this site. In the future, I recommend using the Sandbox to get some reviews

– HyperNeutrino – 2019-08-30T04:29:00.157

1before posting the challenge to the main site. Please ping me here or in chat if you edit this question such that it is not a duplicate and has no unobservable requirements so I can revert the duplicate mark (if I hammer more than once); alternatively, if the challenge is significantly different enough to not be a duplicate, consider rewriting it into Sandbox. – HyperNeutrino – 2019-08-30T04:30:18.810

@HyperNeutrino Thanks for the feedback. I will copy this over to the sandbox and see where it goes. – BLuFeNiX – 2019-08-30T23:46:07.497

I have posted a modified version of my question here: https://codegolf.meta.stackexchange.com/a/18038/88942

– BLuFeNiX – 2019-08-31T00:57:41.310

Answers

0

Python 2.7 and Bash, 45 bytes

x="hello world"
''''echo $x;exit #'''
print x

Adding 1 byte can make it Python 3 compatible as well -- print(x)

Explanation by line:

  1. Variable assignment valid in both languages
  2. Python comment ''' with an extra ' will be interpreted as 0-length string concatenation in bash, followed by echo and exit. The #''' closes the python comment block, but is preceded by a bash comment, so it will be ignored
  3. Python print (bash will exit before getting here, so it won't complain)

BLuFeNiX

Posted 2019-08-30T04:03:54.217

Reputation: 95

0

Ruby and Foo, 17 bytes

puts"hello world"

Foo prints everything in the quotes, and Ruby uses a built-in function to output to stdout.

user85052

Posted 2019-08-30T04:03:54.217

Reputation: