ported and regenerated examples.

This commit is contained in:
Jeremy Ashkenas
2010-07-29 00:51:35 -04:00
parent 65c107fc5d
commit 980a663c19
74 changed files with 652 additions and 755 deletions

View File

@@ -1,17 +1,15 @@
(function(){
var volume, winner;
if (ignition === true) {
launch();
}
if (band !== SpinalTap) {
volume = 10;
}
if (!(answer === false)) {
letTheWildRumpusBegin();
}
car.speed < limit ? accelerate() : null;
if (47 === pick || 92 === pick || 13 === pick) {
winner = true;
}
print("My name is " + this.name);
})();
var volume, winner;
if (ignition === true) {
launch();
}
if (band !== SpinalTap) {
volume = 10;
}
if (!(answer === false)) {
letTheWildRumpusBegin();
}
car.speed < limit ? accelerate() : null;
if (47 === pick || 92 === pick || 13 === pick) {
winner = true;
}
print("My name is " + this.name);

View File

@@ -1,24 +1,22 @@
(function(){
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2;
lunch = (function() {
_a = []; _c = ['toast', 'cheese', 'wine'];
for (_b = 0, _d = _c.length; _b < _d; _b++) {
food = _c[_b];
_a.push(eat(food));
}
return _a;
})();
_f = asteroids;
for (_e = 0, _g = _f.length; _e < _g; _e++) {
roid = _f[_e];
_i = asteroids;
for (_h = 0, _j = _i.length; _h < _j; _h++) {
roid2 = _i[_h];
if (roid !== roid2) {
if (roid.overlaps(roid2)) {
roid.explode();
}
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, food, lunch, roid, roid2;
lunch = (function() {
_a = []; _c = ['toast', 'cheese', 'wine'];
for (_b = 0, _d = _c.length; _b < _d; _b++) {
food = _c[_b];
_a.push(eat(food));
}
return _a;
})();
_f = asteroids;
for (_e = 0, _g = _f.length; _e < _g; _e++) {
roid = _f[_e];
_i = asteroids;
for (_h = 0, _j = _i.length; _h < _j; _h++) {
roid2 = _i[_h];
if (roid !== roid2) {
if (roid.overlaps(roid2)) {
roid.explode();
}
}
}
})();
}

View File

@@ -1,5 +1,3 @@
(function(){
var difficulty, greeting;
greeting = "Hello CoffeeScript";
difficulty = 0.5;
})();
var difficulty, greeting;
greeting = "Hello CoffeeScript";
difficulty = 0.5;

View File

@@ -1,6 +1,4 @@
(function(){
/*
CoffeeScript Compiler v0.7.2
Released under the MIT License
*/
})();
/*
CoffeeScript Compiler v0.7.2
Released under the MIT License
*/

View File

@@ -1,12 +1,10 @@
(function(){
var fs;
fs = require('fs');
option('-o', '--output [DIR]', 'directory for compiled code');
task('build:parser', 'rebuild the Jison parser', function() {
var code, dir;
require('jison');
code = require('./lib/grammar').parser.generate();
dir = options.output || 'lib';
return fs.writeFile(("" + dir + "/parser.js"), code);
});
})();
var fs;
fs = require('fs');
option('-o', '--output [DIR]', 'directory for compiled code');
task('build:parser', 'rebuild the Jison parser', function() {
var code, dir;
require('jison');
code = require('./lib/grammar').parser.generate();
dir = options.output || 'lib';
return fs.writeFile(("" + dir + "/parser.js"), code);
});

View File

@@ -1,37 +1,36 @@
(function(){
var Animal, Horse, Snake, sam, tom;
var __extends = function(child, parent) {
var ctor = function(){ };
var Animal, Horse, Snake, sam, tom;
var __extends = function(child, parent) {
var ctor = function(){};
ctor.prototype = parent.prototype;
child.prototype = new ctor();
child.prototype.constructor = child;
if (typeof parent.extended === "function") parent.extended(child);
child.__superClass__ = parent.prototype;
};
Animal = function() {};
Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");
};
Snake = function(name) {
this.name = name;
return this;
};
__extends(Snake, Animal);
Snake.prototype.move = function() {
alert("Slithering...");
return Snake.__superClass__.move.call(this, 5);
};
Horse = function(name) {
this.name = name;
return this;
};
__extends(Horse, Animal);
Horse.prototype.move = function() {
alert("Galloping...");
return Horse.__superClass__.move.call(this, 45);
};
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();
})();
Animal = function(_a) {
this.name = _a;
return this;
};
Animal.prototype.move = function(meters) {
return alert(this.name + " moved " + meters + "m.");
};
Snake = function() {
return Animal.apply(this, arguments);
};
__extends(Snake, Animal);
Snake.prototype.move = function() {
alert("Slithering...");
return Snake.__superClass__.move.call(this, 5);
};
Horse = function() {
return Animal.apply(this, arguments);
};
__extends(Horse, Animal);
Horse.prototype.move = function() {
alert("Galloping...");
return Horse.__superClass__.move.call(this, 45);
};
sam = new Snake("Sammy the Python");
tom = new Horse("Tommy the Palomino");
sam.move();
tom.move();

View File

@@ -1,5 +1,3 @@
(function(){
var cholesterol, healthy;
cholesterol = 127;
healthy = (200 > cholesterol) && (cholesterol > 60);
})();
var cholesterol, healthy;
cholesterol = 127;
healthy = (200 > cholesterol) && (cholesterol > 60);

View File

@@ -1,12 +1,12 @@
(function(){
var date, mood, options;
if (singing) {
mood = greatlyImproved;
}
if (happy && knowsIt) {
clapsHands();
chaChaCha();
}
date = friday ? sue : jill;
options = options || defaultOptions;
})();
var date, mood, options;
if (singing) {
mood = greatlyImproved;
}
if (happy && knowsIt) {
clapsHands();
chaChaCha();
} else {
showIt();
}
date = friday ? sue : jill;
options = options || defaults;

View File

@@ -1,6 +1,4 @@
(function(){
var hi;
hi = function() {
var hi;
hi = function() {
return [document.title, "Hello JavaScript"].join(": ");
};
})();
};

View File

@@ -1,7 +1,5 @@
(function(){
var solipsism, speed;
if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
solipsism = true;
}
speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;
})();
var solipsism, speed;
if ((typeof mind !== "undefined" && mind !== null) && !(typeof world !== "undefined" && world !== null)) {
solipsism = true;
}
speed = (typeof speed !== "undefined" && speed !== null) ? speed : 140;

View File

@@ -1,13 +1,11 @@
(function(){
var eldest, grade;
grade = function(student) {
if (student.excellentWork) {
return "A+";
} else if (student.okayStuff) {
return student.triedHard ? "B" : "B-";
} else {
return "C";
}
};
eldest = 24 > 21 ? "Liz" : "Ike";
})();
var eldest, grade;
grade = function(student) {
if (student.excellentWork) {
return "A+";
} else if (student.okayStuff) {
return student.triedHard ? "B" : "B-";
} else {
return "C";
}
};
eldest = 24 > 21 ? "Liz" : "Ike";

View File

@@ -1,4 +1,2 @@
(function(){
var one, six, three, two;
six = (one = 1) + (two = 2) + (three = 3);
})();
var one, six, three, two;
six = (one = 1) + (two = 2) + (three = 3);

View File

@@ -1,12 +1,11 @@
(function(){
var _a, _b, globals, name;
var __hasProp = Object.prototype.hasOwnProperty;
globals = (function() {
_a = []; _b = window;
for (name in _b) {
if (!__hasProp.call(_b, name)) continue;
_a.push(name);
}
return _a;
})().slice(0, 10);
})();
var _a, _b, _c, globals, name;
var __hasProp = Object.prototype.hasOwnProperty;
globals = (function() {
_b = []; _c = window;
for (name in _c) {
if (!__hasProp.call(_c, name)) continue;
_a = _c[name];
_b.push(name);
}
return _b;
})().slice(0, 10);

View File

@@ -1,9 +1,7 @@
(function(){
alert((function() {
try {
return nonexistent / undefined;
} catch (error) {
return "And the error is ... " + error;
}
})());
})();
alert((function() {
try {
return nonexistent / undefined;
} catch (error) {
return "And the error is ... " + error;
}
})());

View File

@@ -1,15 +1,11 @@
(function(){
var Account;
Account = function(customer, cart) {
this.customer = customer;
this.cart = cart;
return $('.shopping_cart').bind('click', (function(__this) {
var __func = function(event) {
return this.customer.purchase(this.cart);
};
return (function() {
return __func.apply(__this, arguments);
});
})(this));
var Account;
var __bind = function(func, context) {
return function(){ return func.apply(context, arguments); };
};
})();
Account = function(customer, cart) {
this.customer = customer;
this.cart = cart;
return $('.shopping_cart').bind('click', __bind(function(event) {
return this.customer.purchase(this.cart);
}, this));
};

View File

@@ -1,9 +1,7 @@
(function(){
var cube, square;
square = function(x) {
return x * x;
};
cube = function(x) {
return square(x) * x;
};
})();
var cube, square;
square = function(x) {
return x * x;
};
cube = function(x) {
return square(x) * x;
};

View File

@@ -1,4 +1,2 @@
(function(){
var html;
html = '<strong>\n cup of coffeescript\n</strong>';
})();
var html;
html = '<strong>\n cup of coffeescript\n</strong>';

View File

@@ -1,5 +1,3 @@
(function(){
var author, quote;
author = "Wittgenstein";
quote = ("A picture is a fact. -- " + author);
})();
var author, quote;
author = "Wittgenstein";
quote = ("A picture is a fact. -- " + author);

View File

@@ -1,6 +1,4 @@
(function(){
var dates, sentence, sep;
sentence = ("" + (22 / 7) + " is a decent approximation of π");
sep = "[.\\/\\- ]";
dates = (new RegExp(("\\d+" + sep + "\\d+" + sep + "\\d+"), "g"));
})();
var dates, sentence, sep;
sentence = ("" + (22 / 7) + " is a decent approximation of π");
sep = "[.\\/\\- ]";
dates = /\d+$sep\d+$sep\d+/g;

View File

@@ -1,10 +1,8 @@
(function(){
var _a, city, forecast, temp, weatherReport;
weatherReport = function(location) {
return [location, 72, "Mostly Sunny"];
};
_a = weatherReport("Berkeley, CA");
city = _a[0];
temp = _a[1];
forecast = _a[2];
})();
var _a, city, forecast, temp, weatherReport;
weatherReport = function(location) {
return [location, 72, "Mostly Sunny"];
};
_a = weatherReport("Berkeley, CA");
city = _a[0];
temp = _a[1];
forecast = _a[2];

View File

@@ -1,18 +1,16 @@
(function(){
var _a, _b, age, ages, child, yearsOld;
var __hasProp = Object.prototype.hasOwnProperty;
yearsOld = {
max: 10,
ida: 9,
tim: 11
};
ages = (function() {
_a = []; _b = yearsOld;
for (child in _b) {
if (!__hasProp.call(_b, child)) continue;
age = _b[child];
_a.push(child + " is " + age);
}
return _a;
})();
})();
var _a, _b, age, ages, child, yearsOld;
var __hasProp = Object.prototype.hasOwnProperty;
yearsOld = {
max: 10,
ida: 9,
tim: 11
};
ages = (function() {
_a = []; _b = yearsOld;
for (child in _b) {
if (!__hasProp.call(_b, child)) continue;
age = _b[child];
_a.push(child + " is " + age);
}
return _a;
})();

View File

@@ -1,17 +1,15 @@
(function(){
var _a, _b, _c, city, futurists, name, street;
futurists = {
sculptor: "Umberto Boccioni",
painter: "Vladimir Burliuk",
poet: {
name: "F.T. Marinetti",
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
}
};
_a = futurists;
_b = _a.poet;
name = _b.name;
_c = _b.address;
street = _c[0];
city = _c[1];
})();
var _a, _b, _c, city, futurists, name, street;
futurists = {
sculptor: "Umberto Boccioni",
painter: "Vladimir Burliuk",
poet: {
name: "F.T. Marinetti",
address: ["Via Roma 42R", "Bellagio, Italy 22021"]
}
};
_a = futurists;
_b = _a.poet;
name = _b.name;
_c = _b.address;
street = _c[0];
city = _c[1];

View File

@@ -1,10 +1,12 @@
(function(){
var ages, matrix, song;
song = ["do", "re", "mi", "fa", "so"];
ages = {
max: 10,
ida: 9,
tim: 11
};
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];
})();
var ages, matrix, singers, song;
song = ["do", "re", "mi", "fa", "so"];
singers = {
Jagger: 'Rock',
Elvis: 'Roll'
};
ages = {
max: 10,
ida: 9,
tim: 11
};
matrix = [1, 0, 1, 0, 0, 1, 1, 1, 0];

View File

@@ -1,5 +1,3 @@
(function(){
$('.account').css({
'class': 'active'
});
})();
$('.account').css({
'class': 'active'
});

View File

@@ -1,37 +1,34 @@
(function(){
var _a, _b, _c, _d, cubes, list, math, num, number, opposite, race, square;
var __slice = Array.prototype.slice;
number = 42;
opposite = true;
if (opposite) {
number = -42;
var _a, _b, _c, _d, cubes, list, math, num, number, opposite, race, square;
var __slice = Array.prototype.slice;
number = 42;
opposite = true;
if (opposite) {
number = -42;
}
square = function(x) {
return x * x;
};
list = [1, 2, 3, 4, 5];
math = {
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
}
square = function(x) {
return x * x;
};
list = [1, 2, 3, 4, 5];
math = {
root: Math.sqrt,
square: square,
cube: function(x) {
return x * square(x);
}
};
race = function(winner) {
var runners;
var _a = arguments.length, _b = _a >= 2;
runners = __slice.call(arguments, 1, _a - 0);
return print(winner, runners);
};
if (typeof elvis !== "undefined" && elvis !== null) {
alert("I knew it!");
};
race = function(winner) {
var runners;
runners = __slice.call(arguments, 1);
return print(winner, runners);
};
if (typeof elvis !== "undefined" && elvis !== null) {
alert("I knew it!");
}
cubes = (function() {
_a = []; _c = list;
for (_b = 0, _d = _c.length; _b < _d; _b++) {
num = _c[_b];
_a.push(math.cube(num));
}
cubes = (function() {
_a = []; _c = list;
for (_b = 0, _d = _c.length; _b < _d; _b++) {
num = _c[_b];
_a.push(math.cube(num));
}
return _a;
})();
})();
return _a;
})();

View File

@@ -1,8 +1,6 @@
(function(){
var _a, theBait, theSwitch;
theBait = 1000;
theSwitch = 0;
_a = [theSwitch, theBait];
theBait = _a[0];
theSwitch = _a[1];
})();
var _a, theBait, theSwitch;
theBait = 1000;
theSwitch = 0;
_a = [theSwitch, theBait];
theBait = _a[0];
theSwitch = _a[1];

View File

@@ -1,9 +1,7 @@
(function(){
var _a, close, contents, open, tag;
var __slice = Array.prototype.slice;
tag = "<impossible>";
_a = tag.split("");
open = _a[0];
contents = __slice.call(_a, 1, _a.length - 1);
close = _a[_a.length - 1];
})();
var _a, close, contents, open, tag;
var __slice = Array.prototype.slice;
tag = "<impossible>";
_a = tag.split("");
open = _a[0];
contents = __slice.call(_a, 1, _a.length - 1);
close = _a[_a.length - 1];

View File

@@ -1,5 +1,3 @@
(function(){
String.prototype.dasherize = function() {
return this.replace(/_/g, "-");
};
})();
String.prototype.dasherize = function() {
return this.replace(/_/g, "-");
};

View File

@@ -1,21 +1,19 @@
(function(){
var _a, countdown, deliverEggs, num;
countdown = (function() {
_a = [];
for (num = 10; num >= 1; num--) {
_a.push(num);
}
return _a;
})();
deliverEggs = function() {
var _b, _c, dozen, i;
_b = []; _c = eggs.length;
for (i = 0; (0 <= _c ? i < _c : i > _c); i += 12) {
_b.push((function() {
dozen = eggs.slice(i, i + 12);
return deliver(new eggCarton(dozen));
})());
}
return _b;
};
var _a, countdown, deliverEggs, num;
countdown = (function() {
_a = [];
for (num = 10; num >= 1; num--) {
_a.push(num);
}
return _a;
})();
deliverEggs = function() {
var _b, _c, dozen, i;
_b = []; _c = eggs.length;
for (i = 0; (0 <= _c ? i < _c : i > _c); i += 12) {
_b.push((function() {
dozen = eggs.slice(i, i + 12);
return deliver(new eggCarton(dozen));
})());
}
return _b;
};

View File

@@ -1,11 +1,8 @@
(function(){
var changeNumbers, inner, outer;
outer = 1;
changeNumbers = function() {
var inner;
inner = -1;
outer = 10;
return outer;
};
inner = changeNumbers();
})();
var changeNumbers, inner, outer;
outer = 1;
changeNumbers = function() {
var inner;
inner = -1;
return (outer = 10);
};
inner = changeNumbers();

View File

@@ -1,6 +1,4 @@
(function(){
var copy, numbers, threeToSix;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
threeToSix = numbers.slice(3, 6 + 1);
copy = numbers.slice(0, numbers.length);
})();
var copy, numbers, threeToSix;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
threeToSix = numbers.slice(3, 6 + 1);
copy = numbers.slice(0, numbers.length);

View File

@@ -1,4 +1,2 @@
(function(){
var _a, _b;
(_b = (typeof (_a = (lottery.drawWinner())) === "undefined" || _a == undefined ? undefined : _a.address)) == undefined ? undefined : _b.zipcode;
})();
var _a, _b;
(_b = (typeof (_a = (lottery.drawWinner())) === "undefined" || _a == undefined ? undefined : _a.address)) == undefined ? undefined : _b.zipcode;

View File

@@ -1,18 +1,15 @@
(function(){
var awardMedals, contenders, gold, rest, silver;
var __slice = Array.prototype.slice;
gold = (silver = (rest = "unknown"));
awardMedals = function(first, second) {
var _a = arguments.length, _b = _a >= 3;
rest = __slice.call(arguments, 2, _a - 0);
gold = first;
silver = second;
rest = rest;
return rest;
};
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
awardMedals.apply(this, contenders);
alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + rest);
})();
var awardMedals, contenders, gold, rest, silver;
var __slice = Array.prototype.slice;
gold = (silver = (rest = "unknown"));
awardMedals = function(first, second) {
var others;
others = __slice.call(arguments, 2);
gold = first;
silver = second;
return (rest = others);
};
contenders = ["Michael Phelps", "Liu Xiang", "Yao Ming", "Allyson Felix", "Shawn Johnson", "Roman Sebrle", "Guo Jingjing", "Tyson Gay", "Asafa Powell", "Usain Bolt"];
awardMedals.apply(this, contenders);
alert("Gold: " + gold);
alert("Silver: " + silver);
alert("The Field: " + rest);

View File

@@ -1,5 +1,3 @@
(function(){
var numbers;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));
})();
var numbers;
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
numbers.splice.apply(numbers, [3, 6 - 3 + 1].concat([-3, -4, -5, -6]));

View File

@@ -1,9 +1,7 @@
(function(){
var mobyDick;
mobyDick = "Call me Ishmael. Some years ago -- \
var mobyDick;
mobyDick = "Call me Ishmael. Some years ago -- \
never mind how long precisely -- having little \
or no money in my purse, and nothing particular \
to interest me on shore, I thought I would sail \
about a little and see the watery part of the \
world...";
})();
world...";

View File

@@ -1,18 +1,16 @@
(function(){
if (day === "Mon") {
goToWork();
} else if (day === "Tue") {
goToThePark();
} else if (day === "Thu") {
goIceFishing();
} else if (day === "Fri" || day === "Sat") {
if (day === bingoDay) {
goToBingo();
goDancing();
}
} else if (day === "Sun") {
goToChurch();
} else {
goToWork();
if (day === "Mon") {
goToWork();
} else if (day === "Tue") {
goToThePark();
} else if (day === "Thu") {
goIceFishing();
} else if (day === "Fri" || day === "Sat") {
if (day === bingoDay) {
goToBingo();
goDancing();
}
})();
} else if (day === "Sun") {
goToChurch();
} else {
goToWork();
}

View File

@@ -1,10 +1,8 @@
(function(){
try {
allHellBreaksLoose();
catsAndDogsLivingTogether();
} catch (error) {
print(error);
} finally {
cleanUp();
}
})();
try {
allHellBreaksLoose();
catsAndDogsLivingTogether();
} catch (error) {
print(error);
} finally {
cleanUp();
}

View File

@@ -1,20 +1,18 @@
(function(){
var _a, lyrics, num;
if (this.studyingEconomics) {
while (supply > demand) {
buy();
}
while (!(supply > demand)) {
sell();
}
var _a, lyrics, num;
if (this.studyingEconomics) {
while (supply > demand) {
buy();
}
num = 6;
lyrics = (function() {
_a = [];
while (num -= 1) {
_a.push(num + " little monkeys, jumping on the bed. \
while (!(supply > demand)) {
sell();
}
}
num = 6;
lyrics = (function() {
_a = [];
while (num -= 1) {
_a.push(num + " little monkeys, jumping on the bed. \
One fell out and bumped his head.");
}
return _a;
})();
})();
}
return _a;
})();