JuliaLang / Juleps

Julia Enhancement Proposals
Other
67 stars 24 forks source link

Python to Julia transpiler #55

Closed kiwi0fruit closed 5 years ago

kiwi0fruit commented 5 years ago

It would be nice to have Transpiler from subset of Python (and special ~pythonjulia module named like "Juthon") to complete Julia lang.

And a dream looks like it should both be:

  1. A standalone transpiler so that the user can write "Juthon" package and contribute it to the Julia ecosystem by transpiling.
  2. And runtime decorator style transpiler (with interface like Numba has) that calls Julia (or compiled python library in the future) from Python. So that a small piece of code can be added right in the Python app written in Python.

A good example of a transipiler from Python is Transcrypt that is a valid Python prior transpiling. But to achieve 1. this should be more like Julia in Python syntax (via IDE friendly mapping and juthon module with well-documented stubs) than attempt to implement Python's standard library.

The idea came from this discussion: Why Julia? Will Python/Numba and Python/Cython lose to Julia?

kiwi0fruit commented 5 years ago

@ViralBShah It was off topic there so I opened this issue.

MikeInnes commented 5 years ago

This is not really appropriate for a Julep, since it doesn't need to be in the core language; if you're interested in the idea you could do it as a package (see LispSyntax.jl for inspiration). If you want to discuss the idea you'd be welcome to do so on https://discourse.julialang.org.

kiwi0fruit commented 5 years ago

Thanks for the link to the discourse.

StefanKarpinski commented 5 years ago

Most of Julia's ability to resolve dynamism with performance comes from language design choices, not clever JIT technology. For example, Julia does not do tracing, it just analyzes code ahead of execution and generates good machine code from what you wrote. So transpiling Python to Julia would provide few performance benefits since you would still be stuck with all of the design choices in the Python language that make it so hard to execute efficiently. Don't take if from me, you can watch this excellent talk by Armin Ronacher on "How Python was Shaped by Leaky Internals" which does a much better job addressing the Python side of this issue than I ever could. For understanding the Julia side and how the language's design allows resolving performance with dynamism, there happens to be a paper we wrote on just that subject that you can check out.

kiwi0fruit commented 5 years ago

Sounds unreasonable if you you remember what a transpiler is. It's not an interpreter. It's merely a mapping from one language to another. I bet there is no Julia language construction (together with all optimization flags) that cannot be written in valid Python (expect custom operators and like) with decorators (or special transpiler directives like in Transcrypt).

Ideally transpiler maps some special Python dialect to Julia near surjectively.

kiwi0fruit commented 5 years ago

UPD: Not simply Python dialect but dialect and subset of Python.

KristofferC commented 5 years ago

Again,

If you want to discuss the idea you'd be welcome to do so on https://discourse.julialang.org.