TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: a compiler from Python syntax to JavaScript syntax (like CoffeeScript)

32 点作者 endian超过 14 年前

9 条评论

daeken超过 14 年前
I built something similar a while back (guess it's been in use for about two years now -- built it to support my company's product): <a href="http://github.com/daeken/Pyvascript" rel="nofollow">http://github.com/daeken/Pyvascript</a><p>Key difference between Pyvascript and the other compilers I've seen is a facility for macros performing arbitrary AST manipulations. E.g. in the Pylons environment, you can use _uriOf(Controller.someAction) to have it generate a url in your JS code at compile-time.<p>Always nice to see competition among compilers, though.
jiaaro超过 14 年前
I think that python is sufficiently different from javascript that you'll need to provide your own documentation beyond explaining the transformation.<p>Coffeescript is mostly just javascript shorthand; Python on the otherhand has language features with no javascript equivalent (I'm thinking keyword arguments, generator functions, classes, and especially super() here)<p>That being said, I think to make this project really work you're going to be responsible for documenting the dom, and providing support for libraries like jQuery.
评论 #1848784 未加载
extension超过 14 年前
Here's my thing like this for Ruby:<p><a href="http://github.com/jedediah/prettyscript" rel="nofollow">http://github.com/jedediah/prettyscript</a><p>I abandoned it when CoffeeScript appeared, but you might find something interesting there.
tjarratt超过 14 年前
This is a really neat idea, and I'm definitely going to look into this more when I have time, but I have a small nit to pick.<p>print(...) is a common debugging, or output call in python, and I can see how in many use cases that would translate to console.log in javascript.<p>However, some browsers don't support console.log, and in serverside javascript, objects like console and window are not available. I don't know of any common output technique that would work in all browsers as well as with node.js and ringo. Depending on how much you care about supporting serverside js and different browsers, this may be a non-issue.
评论 #1848899 未加载
endian超过 14 年前
Feedback welcome. And if you encounter any problems, I'll fix 'em quickly.
JeffJenkins超过 14 年前
I wrote one of these for a project. The trouble is that to write functioning python code, even for just the primitives, you have to add a lot of extra scaffolding. I eventually stopped working on it since Pyjamas seemed to be doing a much more complete job (<a href="http://pyjs.org/" rel="nofollow">http://pyjs.org/</a>).<p>I may still write a limited one for use in creating code blocks in my project MongoAlchemy (<a href="http://mongoalchemy.org/" rel="nofollow">http://mongoalchemy.org/</a>).
reinhardt超过 14 年前
A more conservative (i.e. closer to the generated javascript) approach is pythonicjavascript (<a href="http://code.google.com/p/pythonicjavascript/" rel="nofollow">http://code.google.com/p/pythonicjavascript/</a>). Personally I prefer making Javascript look more like Python (<a href="http://classy.pocoo.org/" rel="nofollow">http://classy.pocoo.org/</a>) than creating yet another language variant with subtle differences from the original.
random42超过 14 年前
For which use cases this compiler would be helpful? I believe python and JavaScript are typically used for different purposes.<p>That being said, it looks fantastic. :)<p>Disclaimer - I do not know JavaScript.
评论 #1849300 未加载
评论 #1849127 未加载
评论 #1849029 未加载
bhiggins超过 14 年前
on the flip side, here's an experiment for converting JavaScript to Python, and then if it turns out to be valid RPython (a subset of Python where among other things the types of variables don't change), converts it to a native executable.<p><a href="http://mozakai.blogspot.com/2010/07/experiments-with-static-javascript-as.html" rel="nofollow">http://mozakai.blogspot.com/2010/07/experiments-with-static-...</a>