I want to change julia and add python like features to it.
Make syntax look like Python but inside it is Julia compiler-based.
Is it possible?
How can I do this?
Thank you
Welcome @vedasulo,
This is going to be an interesting thread I assume! Not an easy first question
What kind for example?
Itâs definitely possible to write a Python parser that gives new semantics to Python syntax and calls out to Julia for execution. It will be a lot of work, though â but doing it on your own would be a great learning experience.
Why do you want to do this? Julias syntax is already quite nice, often nicer than Pythons
For speeding up Python code, there is e.g. Numba, which works technically similar to Julia (type inference, LLVM). Ultimatively, it is limited by the Python syntax, which was never designed for speed.
Or with a transpiler approach like Vala, source code to C/C++ or similar and then convert it into an executable file. Vala can do more than C, although it is translated to C with the help of GObject. Depends on what you want but better than Java despite similar syntax in the object-oriented approach
wow it is build just in 2020.
I am wandering if it is possible
like everything why python makes the best programming language.
This is answered in the Julia FAQ
I was just going to post the same link, but you beat me to it .
That said, if you just want Juliaâs surface syntax to look more python-like, âall you would need to doâ is replace this file, which contains Juliaâs parser with your own parser that translates a syntax oriented after Python to Juliaâs s-expression like AST and then just plug that into all the later stages of the compiler. That said, this is likely quite a bit of work and itâs not clear whether it will actually be worth it, since the new language you will just have invented might look a lot like Python on the surface, but will still inherit everything else about Juliaâs behavior, that makes it different from Python. You wonât just be able to run any non-trivial Python code with your new language, but you would still have to rewrite large parts of it, and a language that looks like Python, but doesnât behave like Python might end up being more confusing to Python users than just learning a new language.
Thank you @stevengj and all guys.
It is not possible may, be because as people told, it is hard to manage syntax with julia when syntax is converted to python.
I am not sure what that means, but syntax here is a red herring. What makes Julia special is its semantics, that could â in principle â accommodate a wide variety of surface syntaxes. See eg
If you want to create Python-like Language with some features of Julia, but the advantages of Julia lie in front-end, not the back-end, as it is explained in the pointed-out manual, then why cannot you just work on your language exprwhich are implemented in interpreted languages, then essions until you can generate a code of Julia, which wonât mean you generating lotâs of Julia code for one python line?
If Juliaâs advantage is that it does not use some special features, which are implemented in interpreted languages, then make this syntax more complicated and hard in your language.
Me myself I am also hacking something about Julia, because I donât like, why it cannot let me iterate over Complex objects - I solved definitely, why I can iterate over Complex numbers. All the functions I use are very definite they donât fail any theorem there.
you can âaddâ syntax with macros, if what you want are specific idioms, which is usually what people mean when they say âpythonicâ, i think.
It could be fun to write a string macro to accept âpythonic juliaâ and emit actual julia. I wonder how far you could get before an insurmountable problem. Maybe youâd start by making indentation meaningful so you could write
function f(x, y):
if x>2:
return y
else:
return 2*y
and it would transform to
function f(x, y)
if x>2
y
else
2*y
end
end