OneLang – A tool to help writing code in multiple languages at the same time
ide.onelang.io
ide.onelang.io
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!
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?
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.
FWIW it does figure out that I am running node for v6.11.2.
[0] https://en.wikipedia.org/wiki/Whitespace_(programming_langua...
"OneLang is the love child of @koczkatamas and it was not a planned child. .... OneLang is six months old at the time of writing and it already speaks, but don't expect any comfortable conversation with it yet. It cannot grow without a loving family, and as a single dad I cannot take care of it alone. It needs more mommies and daddies who can help raise it up."
Cool concept and I actually like the wording, it hints the user, that this is a personal project.
Here is _some_ of the negativity I got: https://www.reddit.com/r/programming/comments/6ori0/kira_is_...
What excites me about your project is the possibility to write core math or business logic once and then expose to multiple environments.
I would recommend presenting projects first in person to people before putting them on the internet for debate.
Imagine how it must be for the people behind Rust. Yet, people from the team regularly show up, are polite and nice and are open to arguments in spite of all the negativity they surely face. I think it is easy to become bitter, suspicious, and unfriendly when faced with social pressure, but they seem to continuously find the arguments in even not so polite comments and patiently give good insights and own arguments.
I think it is a shame that the default tends to be negative comments rather than constructive, but I also recognized that giving into toxic emotions is easy.
If you submit anything there, be prepared for harsh criticism. There is some real value in there, but encouragement and cheerings won't come from there.
It's not like this was created for Oracle to use. We don't have to wear suits all the time.
The most limited & basic kinds of static analysis are technically possible, but why not just start with an entirely static language and translate from that to dynamic languages? Would seem much simpler...
I can't speak for the author, but I can think of several reasons I might choose JS:
1. Almost everyone working on the web knows it, so not knowing the source language won't be a roadblock right away.
2. Precisely because of the issues you mentioned, JS is a lot easier to translate with perfect (or close to perfect) fidelity. If the source were something like Haskell, every translation would be very lossy.
3. JS has no boilerplate, like setting up a class or something. You can just type statements.
4. OneLang itself is written in TS, which means working with JS as the source might be easier than, say, C#.
On the contrary, the fewer restrictions a language has, the more difficult it becomes to translate it into languages with stricter requirements. If this were built on JavaScript and not TypeScript, it couldn't even generate the correct type annotations for the other languages that require them. I doubt that this project is going to grow a Haskell backend anytime soon.
Amusing anyhow.
Also: please make it python 3. It's been 13 years...
From lib.d.ts:
interface Math {
// ...
/** Returns a pseudorandom number between 0 and 1. */
random(): number;
// ...
}I am probably not emphasizing this enough, but One is currently a "toolkit" for converting syntax between languages.
`Math.random()` is ~a standard library function. One has limited knowledge about language's StdLibs. But you can make `Math.random` (or any method) work without modifying the compiler, only by adding the appropriate implementation and StdLib definitions to appropriate files. (Even now only using the WebIDE).
The plan is to make One plugin-able and create a "package" manager infrastructure, so anybody can implement `Math.random()` or any other methods, publish it and then you can just download that package.
Implementing every language's StdLib is not a one-man job, so I've always considered this out-of-scope.
Sorry if any published information regarding this was misleading.
I would have seriously considered your option at the time.
I have no time to dive into this now but I'll bookmark it and come to wave at your gitter.
Is it realistic to contribute to it with knowledge of C++/C#/Java/Python but a pretty poor grasp of JS?
Python 2 is dead. Long live Python 3.
Question: Can it support plain JS -> other languages? Or does it have to be TypeScript? How could plain JS support be added?
I got into a project years ago with this ambition using an AST and allowing each language to provide their own translation for each syntax element or block of code.
It also had the unique benefit of being able to take larger blocks like a function and allowing the translator to provide a full function in some native programming language so that a login or Fibonacci function could have multiple translations in the same language allowing the translation to evolve and adapt to use the most efficient one as new translations were introduced.
But yeah, generally only a limited subset of a language is supported. This is the price of writing code targeting multiple language. That's why you cannot (and probably won't be able to) convert existing code.
Tl;dr: you cannot use One in production now, but the grand plan is to make One as hackable and flexible as I can.
So here is the plan:
- the compiler does not contain any target language-specific part, you can add a new language by creating a few hundred lines of template file (this actually works already, it is not just a plan)
- rewrite One in One, so you can convert from any language to any language in any language
- there is no StdLib, but libraries can be created by anyone. We publish interface and implementation definition separately, and you can eg. implement a Web client interface for PHP and Node, while somebody else can implement it for C# and Swift. Behaviour defined by interface tests, if your implementation passes interface test => good. If there is no test for an edge-case => undefined behaviour. Read more here: https://github.com/koczkatamas/onelang/issues/9
- you write a library in One and it helps you to publish to every language's package manager (npm, pip, NuGet, etc). You can reach much more developer with your library compared to targeting only one lang's developer base
The language specific implementations of those interfaces could be mined(by hand or automated) for coins to directly incentivise engineering effort. The block acceptance would be based on the universal tests/benchmarks passing.
My program is i=1 and the Java program it produces is:
class Program { public static void main(String[] args) throws Exception { i = 1; } }
which is wrong because "i" must be defined in java as in "int i;"
[1] https://haxe.org
The first requirement seems to be a go ( https://api.haxe.org/haxe/Http.html ) but i'm not sure of other variables for implementing this
Other sources:
For some reason, the first time I looked at Haxe I got the impression that Haxe is an open-source Flash / Flash successor. (Mostly, I think, because Flash keeps getting mentioned with projects associated with Haxe, like OpenFL and Flambe, and several times in the Haxe Wikipedia article).
Clearly Haxe isn't "just" an open Flash, but how is Haxe related to Flash?
https://haxe.org/manual/target-flash-getting-started.html
If you have ever tried to write Flash applets the old-fashioned way, it feels more like a scriptable paint program.
Some languages can't be parsed without solving the halting problem, but even in such cases, you can simply bundle it with an interpreter in the target language. And the subset of programs humans are actually likely to write should be much saner.