addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1light-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

Re: [nycpython] PYXC-PJ: a Python to Javascript compiler

From: Dan F.
Sent on: Saturday, October 30, 2010 11:21 AM
If your click handlers, controllers, and callbacks are all python, can you test your ajax end-to-end with a python unit test? ?I think it'd be awesome if you worked toward that.

dan

On Sat, Oct 30, 2010 at 10:52 AM, Andrew Schaaf <[address removed]> wrote:

On Oct 29, 2010, at 8:20 PM, Patrick wrote:
How would you use a library like jquery in javascript with this? If
there's any reason too?

script src="...jquery.js"
script src="...my-compiled-code.js"

Since Python doesn't support $ as a name, you can use jQuery's other name: "jQuery"
J = jQuery
J(document).ready(...)


On Oct 30, 2010, at 7:22 AM, david jensen wrote:
Did you try making this work with Google's Closure?

Closure Compiler? Absolutely. I always minify my JS using Closure's simple-optimizations mode.

Closure Library? Sure. Just build the subset you need and include it first as another script.?The?pj-closure?conversion is mostly for fun.

Note: sometime this weekend, PYXC-PJ will?support the inclusion of raw JS files via import statements.?There could also be some optionally-enabled special-casing to follow Closure's dependency graph.

How is is related to?Pyjamas?

(1)?Pyjamas?does way too much**, messing with your output in the name of Python semantics, whereas PYXC-PJ is a direct syntax conversion and the resulting JavaScript is exactly what you expect (after quickly reading about the extremely few special cases).

** "pyjslib?takes care of Python types that require a custom Javascript implementation for pyjs to work. For example, even though Python lists are similar to Javascript arrays, Python lists are converted to custom objects that implement methods such as?append."

(2) I found the Pyjamas transformations source code hard to casually read, whereas with PYXC-PJ, I tried to make each transformation as independent as possible (so you can easily grok or modify the transformations)

Note: the general-purpose (Python --> Anything) code is in pj/pyxc/*, and it might be useful if you're whipping up a (Python --> Something) DSL.

Also, I used?docco?for literate programming.

If you're interested:






On Oct 29, 2010, at 7:51 PM, Ned Batchelder wrote:

It doesn't compile Python semantics into Javascript. ?The label?"Python-to-Javascript?compiler" is a bit of a misnomer. ?As near as?I can tell, it translates "Javascript-with-a-Python-inspired-syntax"?into Javascript.

True. I'll try to improve the wording.


On Oct 29, 2010, at 7:32 PM, Matt Di Pasquale wrote:

Cool. Is there something like this to convert Ruby into JavaScript?


Its author wrote yesterday: "I abandoned it when CoffeeScript appeared, but you might find something interesting there."


On Oct 29, 2010, someone wrote off-list:

Just curious -- any particular reason you wrote this instead of just
using Coffeescript?

  • Python seems more readable to me
  • Python static analysis code will apply to my JavaScript too
  • No mental switching cost when cycling between client-side and server-side window groups
  • Compilers are fun to write, especially when you try to make the transformations readable and independent


- Andrew





--
Please Note: If you hit "REPLY", your message will be sent to everyone on this mailing list ([address removed])
This message was sent by Andrew Schaaf ([address removed]) from The New York Python Meetup Group.
To learn more about Andrew Schaaf, visit his/her member profile
To unsubscribe or to update your mailing list settings, click here

Meetup, PO Box 4668 #37895 New York, New York[masked] | [address removed]

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy