Hey, after a lot of work in the last few weeks I'm finally ready to introduce you to one of our latest projects called PyvaScript. It's a new scripting language for your client side code with a syntax inspired by our favorite language Python. :) So let's take a closer look at what Waldemar conjured up.
The goal of PyvaScript is to solve this problem by giving you the possibility to use a Python like syntax as well as common functions from Python wherever that is possible on the client side too. Thus PyvaScript addresses developers who love Python while still being able to write fast code and interface with JS.
So let's see what PyvaScript looks like:
setup.py install first)
Now you can add "demo.js" to your html file. But before this you have to include PyvaScript's "stdlib.js" containing function definitions used by the compiled source file. So put the following line into the head section of your html files before any compiled PyvaScript file:
That's it. Your first PyvaScript can now run in your browser. :)
- PyvaScript only supports the for-in-loop and optimizes it at compile time.
- You don't have to use the keyword
varanymore to define local variables.
- Global variables can be defined using the keyword
global. You still can use
window.var_definitionbut it's cleaner to use
- You have to use
- Functions are defined via the keyword
- We started to add common functions from Python to PyvaScript. At the moment you can use
joinon strings as well as
extendon arrays while still being able to use
appendfor example. Additionally you can use the
rangefunction in for-loops.
What's different to Python?
While trying to stay as close as possible to Python there are still some differences:
- tuple objects are just lists. This means that they are mutable.
- PyvaScript does neither support keyword arguments nor classes nor any other complex features from Python.
- You can use multi-line lambda functions.
In order to make PyvaScript work you have to keep two things in mind:
- You have to include PyvaScripts "stdlib.js" before any of your compiled PyvaScript files.
- Never call a function
JS. PyvaScript defines a function called
JS('for (var i=0; i< 5; i++) alert(i);')which wouldn't be possible with PyvaScript.
As this is the first version of PyvaScript we will try to extend it wherever possible so that switching between languages will be even less painful. In particular we will focus on the following steps
- Extending PyvaScript with standard methods for strings, lists, ...
- Combining PyvaScript with the PyJS compiler from PyJamas
The last point is especially interesting because PyJS emulates many features from Python. It even includes many modules from Python,