Thursday, August 13th, 2009
Skulpt: Crazy project that lets your browser parse and run Python
<>blockquote>Skulpt is an entirely in-browser implementation of Python.
Really. Crazy and cool.

You can build an example term like this just via:
-
-
window.addEvent('domready', function() {
-
var term = initTerminal(80, 20);
-
-
// set up demo typers
-
$('codeexample1').addEvent('click', (function(e)
-
{
-
e.stop();
-
term.doClear();
-
term.writeStr("print "Hello, World!" # natch", false, true);
-
term.doEnter();
-
}));
-
$('codeexample2').addEvent('click', (function(e)
-
{
-
e.stop();
-
term.doClear();
-
term.writeStr("for i in range(5):", false, true); term.doEnter();
-
term.writeStr(" print i", false, true); term.doEnter();
-
term.doEnter();
-
}));
-
$('codeexample3').addEvent('click', (function(e)
-
{
-
e.stop();
-
term.doClear();
-
term.writeStr("[x*x for x in range(20) if x % 2 == 0]", false, true);
-
term.doEnter();
-
}));
-
-
term.writeStr("Skulpt demo REPL - " + new Date().toLocaleString() + "n");
-
term.writeStr(term.PS1, true);
-
});
-
Related Content:











Who’s up to the challenge of creating a ruby version?
Pretty brilliant. With all these languages-within-a-browser project, I wonder how far we are from having Javascript emulate Java, which could then run a browser? :)
@sixtyseconds:
Looks like someone already did:
http://ajaxian.com/archives/prefer-ruby-syntax-see-red-and-your-ruby-will-convert-to-js
http://wonderfullyflawed.com/2008/10/13/red-40-a-full-ruby-runtime-in-your-browser/
Fun stuff.
Guess what, US keyboard layouts aren’t used worldwide. Some people like their quotes as shift+2.
This has the potential to be all kinds of awesome. I would so much rather my browser code be Python than Javascript. My reasons are mostly cosmetic (I think Python is much cleaner than JS), but still it would be nice to have flexibility in the browser world.
“Guess what, US keyboard layouts aren’t used worldwide. Some people like their quotes as shift+2.”
The guy writes an early-release language-in-a-browser and you complain about localization? Harsh I’d have thought.
Can’t honestly think when I’d use this, but its pretty neat all the same.
Nice work. This is really cool!
@ilithium I thought I saw a java interpreter in javascript once, although I can’t find it anymore.
I want to know how he did it. Surely he didn’t write a Python interpreter from scratch in javascript?!
Now someone produce a JavaScript interpreter in Python, then we can recursively run these recursively inside each other until the universe explodes.
“I want to know how he did it. Surely he didn’t write a Python interpreter from scratch in javascript?!”
I looked at the source. It looks like he did.
JavaScript is already quite inefficient, but JavaScript executing another language? This is surely going to be quite slow, if it works.
My (very unlikely to occur) dream is that the browsers unite on a virtual machine with bytecode and a DOM interface, something like Parrot which can still execute JavaScript as well as Python, Perl6, Ruby, Lua, and tons of other programming languages concurrently.
jhuni, bytecode is my nightmare. Once you have bytecode, you lose the ability for people to learn from looking at the source other people write.
Cool!
I hate to be the voice of grumpiness, but aside from the “oo, look what you can make JavaScript do” factor, what possible use does this have?
RE: jhuni, bytecode is my nightmare. Once you have bytecode, you lose the ability for people to learn from looking at the source other people write.
You already lose that by minification and obfuscation that most production environments implement anyways. It might as well be bytecode. Besides Flash also exists all over production environments and you cannot read its source code either.
Just because bytecode would exist doesn’t mean you couldn’t send JavaScript over anyways and then the JavaScript can get converted to bytecode by the client rather then the server. The advantage is you could also send over Python, Perl, or Ruby so you would not have to use a poorly designed language called JavaScript.
Just started to learn python yesterday in order to use the Google App Engine. Not sure if this is useful but certainly going to have a play around with it.
@jhuni:
Which would imply that Python/Ruby/Perl aren’t badly designed? (Rhetorical question)
@TNO:
Well I did not necessarily say that Python/Ruby/Perl are designed effectively, it is more that between such languages most people could find something they like better then JavaScript.
Indeed, some other crazy guy already made a Ruby virtual machine in Javascript ages ago.
But there are also languages that were explicitely designed to support multiple other languages as targets, including Javascript. haXe ( http://www.haxe.org ) is the best example I can think of, but there must be other ones. haXe can compile for its own VM (Neko) but the same source code can also be translated into C++ (that can even build native iPhone applications), Javascript, PHP and Flash. It’s quite convenient, especially to share code between the client side and the server side.
My favourite langauge-in-javascript is the 6502 compiler: http://www.6502asm.com/ – I just tried it again after seeing this page. Thanks to our new kick-arse JS engines it runs a zillion times faster.
It’s like when you find old games that were made for a 386 where the timing was set to “show as many frames per second as possible”. You think we would have learned the first time ;)
Its sad how we could make the web browser a million times better, but we don’t. You would think competition might be a reason for it to improve. It is not.
Projects like this one illustrate the idiocy of Python’s decision to impart semantic meaning to whitespace. It’s one thing for a *person* to indent code properly in a text editor, and another entirely when the code “writer” is another program.