Writing a Polyglot Script
nkanaev.github.io
nkanaev.github.io
Here is is, if anyone's interested: https://gist.github.com/DarwinAwardWinner/2eb3705fb6ddab08ee...
And here's the Python version: https://gist.github.com/DarwinAwardWinner/8a631d897d45f00552...
#!/bin/bash
Rscript myscript.R (0 and eval(IO.read("ruby.rb"))) or eval(compile(open("python.py").read(), "", "exec"))
Granted, this doesn’t close the Python file, which is delayed until garbage collection or program termination. /*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
//\u000A\u002A\u002F
It's both valid PHP and Java.Not mine, stolen from https://gist.github.com/forairan/b1143f42883b3b0ee1237bc9bd0....
[0] https://www.alchemistowl.org/pocorgtfo/ [1] https://www.alchemistowl.org/pocorgtfo/pocorgtfo19.pdf [2] https://github.com/angea/pocorgtfo [3] https://www.youtube.com/watch?v=W9WnnMJ0RKg
Jupyter's multiple language kernels come close to this, but not quite.
And here's a polyglot notebook example: https://fniephaus.com/2019/px19-polyglot-notebooks.pdf
And finally, here's our GraalVM-powered Jupyter kernel: https://github.com/hpi-swa/ipolyglot
p='"%s"';r="'%s'";_='p=%s;r=%s;_=%s;print(_%%((0and[r%%p,p%%r,r%%_])or(tuple([r%%p,p%%r,r%%_]))))';print(_%((0and[r%p,p%r,r%_])or(tuple([r%p,p%r,r%_]))))
with inspiration from https://stackoverflow.com/q/6223285 and https://stackoverflow.com/a/2475931Evaluating:
p='"%s"';r="'%s'";_='p=%s;r=%s;_=%s;print(_%%((0and[r%%p,p%%r,r%%_])or(tuple([r%%p,p%%r,r%%_]))))';print(_%((0and[r%p,p%r,r%_])or(tuple([r%p,p%r,r%_]))))
becomes: p='"%s"';r="'%s'";_='p=%s;r=%s;_=%s;print(_%%((0and[r%%p,p%%r,r%%_])or(tuple([r%%p,p%%r,r%%_]))))'%_]))))
Too many '%'s in some places