Oct 20, 2008

Worlds: Controlling the Scope of Side Effects

Alessandro Warth and Alan Kay introduce a new language construct to javascript: worlds.

This paper explores the idea of “tabs for programming languages”, which we call worlds.

A world is sort of like a transaction, sort of like a namespace. You sprout a new world from the current world, and then you perform your changes — copy-on-write — and then you choose whether to commit your changes to the world you sprouted from or not. You can try it online here. Here’s an example from the paper, scoped monkey-patching:


ourWorld = thisWorld.sprout();
in ourWorld {
  numberToEnglish = function(n) {
    ...
  };
  Number.prototype.toString = function() {
    return numberToEnglish(this);
  };
}
arr = [1, 2, 3];
in ourWorld { 
  print(arr.toString()); // [one, two, three]
}
print(arr.toString()); // [1, 2, 3]
About
Daily Meh is written and edited by Simen (contact me). I live in Norway. This blog is about whatever interests me. Here are some of my favorite posts from the archives. You can subscribe via RSS.