Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Why not write one piece of code that is simultaneously valid in ~12 languages?

https://github.com/stephane-chazelas/misc-scripts/blob/maste...

I know it takes advantage of some technicalities (end-of-input separators and such), but it's still a remarkably impressive piece of engineering. I put that up there with some really hairy quines (https://github.com/mame/quine-relay), except it can actually be useful!



What are the 12 languages?

I already tried:

node perl python ruby bash tcsh

From the code it is obvious that DOS and php are on the list, but I don't happen to have them.

What are the others?


I'm counting different editions of POSIX-compliant shell languages (e.g. ksh93, zsh, bash, [t]csh) as different, as well as massively different editions of DOS (freeDOS, MSDOS).

Hence the approximating tilde on "~12". Reasonable minds may consider there to be many fewer, or many more, compatible interpreters.

EDIT: There also appear to be multiple compatible JavaScript interpreters--browser V8 (though not Node, oddly--it's detected as generic; I may send a PR sometime), SpiderMonkey, and older IE. I'm no expert on JS runtimes, though, so the differing results I'm observing may be due to something else.


You should add Whitespace [0] to that :)

[0] https://en.wikipedia.org/wiki/Whitespace_(programming_langua...


Thanks.

FWIW it does figure out that I am running node for v6.11.2.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: