Re:Pyjaco - Python to JavaScript translator.
by streptomycin on Monday June 18, 2012 @09:24AM
(#4126269)
Since you seem to be the expert, let me try to bother you...
I'm in the very early stages of porting an app from Python to Javascript, and I have no illusion that it's going to work out of the box from a translator (lots of third party libraries, and switching from server side to client side). But it would be nice if at least some of the obvious syntax could be translated.
However, all of the several translators I've tried simply die with a message like "this library is not supported" or "this language feature isn't supported" and then they produce absolutely no output, which isn't any help at all. Are there any translators that will simply skip over stuff they don't understand while translating stuff they do understand?
Also, side note, those floating boxes on the right side of your blog make it impossible to grab the scrollbar thingie when it is under them, as it is near the top of the page, which is very annoying to me.
Re:Pyjaco - Python to JavaScript translator.
by HerrMonnezza on Tuesday June 19, 2012 @03:42PM
(#4133724)
I'm afraid I'm no expert - I just reviewed the converters because I would have liked to use Python both on the client- and the server-side; however, I eventually abandoned the idea.
I'm not sure how a converter could "skip over stuff it doesn't understand while translating stuff it does understand": it may make sense to work on "small" translation units (e.g., a function or method), but the code that comes out of the translation of a unit should be -at least syntactically- correct in the target language. Indeed, the more mature Python-to-C translators (e.g., Cython) do restrict the Python that are allowed in the source file, and refuse to compile the entire file if your code contains unsupported syntax.
If you are willing to invest some effort into adapting a translator yourself, (besides Pyjaco! :-)) PJS and Py2Js are both very clean and easy to understand/patch. Although they are no longer developed, they might provide a good starting point to build the "simple minded" translator that you would like to have.
(Thanks for the remark on the blog layout - I just picked one of the standard styles and did not pay much attention to the details.)
Re:Pyjaco - Python to JavaScript translator.
by neoel on Monday June 18, 2012 @08:46AM
(#4126120)
Thats the one being in development, Allthough it's going a bit slower recently. There are plans to completely overhaul the project. Since it was built upon fork upon fork. Lots of decisions are outdated.
Re:Pyjaco - Python to JavaScript translator.
by flashingpumpkin on Monday June 18, 2012 @08:12AM
(#4126024)
The issue I had with Pyjamas is that the whole tool-chain and compilation was a bit borked and the documentation a bit vague. After playing around with it for a day I decided it was too cumbersome so I ditched it in the end and tried py2js which Pyjaco is forked from. Mind you that was 2 years ago so a lot might have improved in that time but it convinced me that writing JS in Python is (was) not really feasible.
Re:Pyjaco - Python to JavaScript translator.
by apgwoz on Monday June 18, 2012 @07:47AM
(#4125948)
Does this provide a sane way to deal with callbacks? Obviously, in JavaScript you're writing callbacks all the time, and nested defs (think callbacks which call something that requires a callback... repeat) in Python are ugly and annoying. For example, try writing factorial in CPS style sometime in Python.
Re:Pyjaco - Python to JavaScript translator.
by lucian1900 on Monday June 18, 2012 @08:01AM
(#4125989)
Twisted's Deferreds solve this problem for Python already. They might even work unmodified with this translator, but they are a simple enough concept to re-create if necessary.
Last year, I wrote a comparison of the ones I could find, but none of them actually was in very good shape: http://chargen.blogspot.com/2011/08/survey-of-python-to-java...
I'm in the very early stages of porting an app from Python to Javascript, and I have no illusion that it's going to work out of the box from a translator (lots of third party libraries, and switching from server side to client side). But it would be nice if at least some of the obvious syntax could be translated.
However, all of the several translators I've tried simply die with a message like "this library is not supported" or "this language feature isn't supported" and then they produce absolutely no output, which isn't any help at all. Are there any translators that will simply skip over stuff they don't understand while translating stuff they do understand?
Also, side note, those floating boxes on the right side of your blog make it impossible to grab the scrollbar thingie when it is under them, as it is near the top of the page, which is very annoying to me.
I'm not sure how a converter could "skip over stuff it doesn't understand while translating stuff it does understand": it may make sense to work on "small" translation units (e.g., a function or method), but the code that comes out of the translation of a unit should be -at least syntactically- correct in the target language. Indeed, the more mature Python-to-C translators (e.g., Cython) do restrict the Python that are allowed in the source file, and refuse to compile the entire file if your code contains unsupported syntax.
If you are willing to invest some effort into adapting a translator yourself, (besides Pyjaco! :-)) PJS and Py2Js are both very clean and easy to understand/patch. Although they are no longer developed, they might provide a good starting point to build the "simple minded" translator that you would like to have.
(Thanks for the remark on the blog layout - I just picked one of the standard styles and did not pay much attention to the details.)
Unfortunately, the error reporting of the live demo isn't very helpful at this stage. I quickly ran into some compilation errors:
The unique trouble I found by myself is that list comprehension are not fully supported.
This won't work as expected. I opened an issue about this: https://github.com/chrivers/pyjaco/issues/69True
ok, I love this thing already!
wow, it also knows about bound-methods https://gist.github.com/2947907 , no need to hack with _.bindAll().