Changing the coersion example so it can show difference between computing the value and printing it out.

This commit is contained in:
Danny Yoo 2011-07-18 10:53:23 -04:00
parent 752bc5350e
commit 061ea53805
4 changed files with 29 additions and 33 deletions

View File

@ -9,8 +9,8 @@ handler
"big bang should follow:" "big bang should follow:"
(big-bang 1 (big-bang 1
;;(on-tick add1 1) (on-tick add1 1)
(on-tick (lambda (w) (* w 2)) 1) ;;(on-tick (lambda (w) (* w 2)) 1)
;;(stop-when (lambda (w) (> w 10))) ;;(stop-when (lambda (w) (> w 10)))
) )

View File

@ -44,9 +44,11 @@
try { try {
succ = succ || function(){}; succ = succ || function(){};
fail = fail || function(){}; fail = fail || function(){};
var args = [];
for (var i = 2; i < arguments.length; i++) { var oldArgcount = MACHINE.argcount;
args.push(arguments[i]); MACHINE.argcount = arguments.length - 2;
for (var i = 0; i < arguments.length - 2; i++) {
MACHINE.env.push(arguments[arguments.length - 1 - i]);
} }
// Check arity usage. // Check arity usage.
@ -55,6 +57,10 @@
} }
var result = v.apply(null, args); var result = v.apply(null, args);
MACHINE.argcount = oldArgcount;
for (var i = 0; i < arguments.length - 2; i++) {
MACHINE.env.pop();
}
succ(result); succ(result);
} catch (e) { } catch (e) {
fail(e); fail(e);
@ -68,13 +74,8 @@
succ = succ || function(){}; succ = succ || function(){};
fail = fail || function(){}; fail = fail || function(){};
var args = [], i;
for (i = 2; i < arguments.length; i++) {
args.push(arguments[i]);
}
// Check arity usage. // Check arity usage.
if (! plt.baselib.arity.isArityMatching(v.arity, args.length)) { if (! plt.baselib.arity.isArityMatching(v.arity, arguments.length - 2)) {
throw new Error("arity mismatch"); throw new Error("arity mismatch");
} }
@ -110,25 +111,21 @@
}); });
}; };
setTimeout( MACHINE.control.push(
function() { new plt.baselib.frames.CallFrame(afterGoodInvoke, null));
MACHINE.control.push( MACHINE.argcount = arguments.length - 2;
new plt.baselib.frames.CallFrame(afterGoodInvoke, null)); for (var i = 0; i < arguments.length - 2; i++) {
MACHINE.argcount = args.length; MACHINE.env.push(arguments[arguments.length - 1 - i]);
for (var i = 0; i < args.length; i++) { }
MACHINE.env.push(args[i]); MACHINE.proc = v;
} MACHINE.params['currentErrorHandler'] = function(MACHINE, e) {
MACHINE.proc = v; MACHINE.params['currentErrorHandler'] = oldErrorHandler;
MACHINE.params['currentErrorHandler'] = function(MACHINE, e) { MACHINE.val = oldVal;
MACHINE.params['currentErrorHandler'] = oldErrorHandler; MACHINE.argcount = oldArgcount;
MACHINE.val = oldVal; MACHINE.proc = oldProc;
MACHINE.argcount = oldArgcount; fail(e);
MACHINE.proc = oldProc; };
fail(e); plt.runtime.trampoline(MACHINE, v.label);
};
plt.runtime.trampoline(MACHINE, v.label);
},
0);
}; };
return f; return f;
}; };

View File

@ -13,7 +13,8 @@ plt.runtime.ready(function() {
myFactClosure); myFactClosure);
myFact(function(v) { myFact(function(v) {
$('#answer').text(v.toString()); $('#answer').text('computed. Printing...');
setTimeout(function() { $('#answer').text(v.toString()); }, 0);
}, },
function(err) { function(err) {
$('#answer').text(err.message).css("color", "red"); $('#answer').text(err.message).css("color", "red");

View File

@ -191,7 +191,6 @@ OnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype);
OnDraw.prototype.toRawHandler = function(MACHINE) { OnDraw.prototype.toRawHandler = function(MACHINE) {
var worldFunction = function(world, k) { var worldFunction = function(world, k) {
console.log('about to call the on-draw');
// FIXME: call the handler instead! // FIXME: call the handler instead!
k(plt.baselib.format.toDomNode(world)); k(plt.baselib.format.toDomNode(world));
}; };
@ -213,7 +212,6 @@ DefaultOnDraw.prototype = plt.baselib.heir(WorldConfigOption.prototype);
DefaultOnDraw.prototype.toRawHandler = function(MACHINE) { DefaultOnDraw.prototype.toRawHandler = function(MACHINE) {
var that = this; var that = this;
var worldFunction = function(world, k) { var worldFunction = function(world, k) {
console.log(rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world)));
k([that.toplevelNode, k([that.toplevelNode,
rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))]); rawJsworld.node_to_tree(plt.baselib.format.toDomNode(world))]);
}; };