trying to rip out more things

This commit is contained in:
Danny Yoo 2011-07-03 14:46:43 -04:00
parent 702ced8ec9
commit af2b64b6b8
2 changed files with 83 additions and 88 deletions

View File

@ -167,37 +167,39 @@ if (! this['plt']) { this['plt'] = {}; }
var throwCheckError = function(details, pos, args) { // var throwCheckError = function(details, pos, args) {
var errorFormatStr; // var errorFormatStr;
if (args && args.length > 1) { // if (args && args.length > 1) {
var errorFormatStrBuffer = ['~a: expects type <~a> as ~a arguments, given: ~s; other arguments were:']; // var errorFormatStrBuffer = ['~a: expects type <~a> as ~a arguments, given: ~s; other arguments were:'];
for (var i = 0; i < args.length; i++) { // for (var i = 0; i < args.length; i++) {
if ( i != pos-1 ) { // if ( i != pos-1 ) {
errorFormatStrBuffer.push(toWrittenString(args[i])); // errorFormatStrBuffer.push(toWrittenString(args[i]));
} // }
} // }
errorFormatStr = errorFormatStrBuffer.join(' '); // errorFormatStr = errorFormatStrBuffer.join(' ');
} // }
else { // else {
errorFormatStr = "~a: expects argument of type <~a>, given: ~s"; // errorFormatStr = "~a: expects argument of type <~a>, given: ~s";
details.splice(2, 1); // details.splice(2, 1);
} // }
raise( types.incompleteExn(types.exnFailContract, // raise( types.incompleteExn(types.exnFailContract,
helpers.format(errorFormatStr, details), // helpers.format(errorFormatStr, details),
[]) ); // []) );
}; // };
var check = function(x, f, functionName, typeName, position, args) {
if ( !f(x) ) {
throwCheckError([functionName, // var check = function(x, f, functionName, typeName, position, args) {
typeName, // if ( !f(x) ) {
helpers.ordinalize(position), // throwCheckError([functionName,
x], // typeName,
position, // helpers.ordinalize(position),
args); // x],
} // position,
}; // args);
// }
// };
var isList = function(x) { var isList = function(x) {
var seenPairs = makeLowLevelEqHash(); var seenPairs = makeLowLevelEqHash();
@ -235,16 +237,16 @@ if (! this['plt']) { this['plt'] = {}; }
} }
}; };
var checkListOf = function(lst, f, functionName, typeName, position, args) { // var checkListOf = function(lst, f, functionName, typeName, position, args) {
if ( !isListOf(lst, f) ) { // if ( !isListOf(lst, f) ) {
helpers.throwCheckError([functionName, // helpers.throwCheckError([functionName,
'list of ' + typeName, // 'list of ' + typeName,
helpers.ordinalize(position), // helpers.ordinalize(position),
lst], // lst],
position, // position,
args); // args);
} // }
}; // };
// // remove: array any -> array // // remove: array any -> array
@ -914,11 +916,11 @@ if (! this['plt']) { this['plt'] = {}; }
helpers.reportError = reportError; helpers.reportError = reportError;
helpers.raise = raise; helpers.raise = raise;
helpers.throwCheckError = throwCheckError; // helpers.throwCheckError = throwCheckError;
helpers.isList = isList; helpers.isList = isList;
helpers.isListOf = isListOf; helpers.isListOf = isListOf;
helpers.check = check; // helpers.check = check;
helpers.checkListOf = checkListOf; // helpers.checkListOf = checkListOf;
// helpers.remove = remove; // helpers.remove = remove;
helpers.map = map; helpers.map = map;

View File

@ -648,21 +648,6 @@ if (! this['plt']) { this['plt'] = {}; }
return this; return this;
}; };
Empty.prototype.first = function() {
helpers.raise(types.incompleteExn(
types.exnFailContract,
"first can't be applied on empty.",
[]));
};
Empty.prototype.rest = function() {
helpers.raise(types.incompleteExn(
types.exnFailContract,
"rest can't be applied on empty.",
[]));
};
Empty.prototype.isEmpty = function() {
return true;
};
Empty.prototype.toWrittenString = function(cache) { return "empty"; }; Empty.prototype.toWrittenString = function(cache) { return "empty"; };
Empty.prototype.toDisplayedString = function(cache) { return "empty"; }; Empty.prototype.toDisplayedString = function(cache) { return "empty"; };
Empty.prototype.toString = function(cache) { return "()"; }; Empty.prototype.toString = function(cache) { return "()"; };
@ -689,7 +674,7 @@ if (! this['plt']) { this['plt'] = {}; }
Cons.prototype.reverse = function() { Cons.prototype.reverse = function() {
var lst = this; var lst = this;
var ret = Empty.EMPTY; var ret = Empty.EMPTY;
while (!lst.isEmpty()){ while (!isEmpty(lst)){
ret = Cons.makeInstance(lst.first, ret); ret = Cons.makeInstance(lst.first, ret);
lst = lst.rest; lst = lst.rest;
} }
@ -710,9 +695,6 @@ if (! this['plt']) { this['plt'] = {}; }
}; };
Cons.prototype.isEmpty = function() {
return false;
};
// Cons.append: (listof X) -> (listof X) // Cons.append: (listof X) -> (listof X)
@ -721,7 +703,7 @@ if (! this['plt']) { this['plt'] = {}; }
return this; return this;
var ret = b; var ret = b;
var lst = this.reverse(); var lst = this.reverse();
while ( !lst.isEmpty() ) { while ( !isEmpty(lst) ) {
ret = Cons.makeInstance(lst.first, ret); ret = Cons.makeInstance(lst.first, ret);
lst = lst.rest; lst = lst.rest;
} }
@ -1252,7 +1234,7 @@ String.prototype.toDisplayedString = function(cache) {
var schemeChangeWorld = new PrimProc('update-world', 1, false, false, var schemeChangeWorld = new PrimProc('update-world', 1, false, false,
function(worldUpdater) { function(worldUpdater) {
//helpers.check(worldUpdater, helpers.procArityContains(1), //helpers.check(worldUpdater, helpers.procArityContains(1),
'update-world', 'procedure (arity 1)', 1); // 'update-world', 'procedure (arity 1)', 1);
return new INTERNAL_PAUSE( return new INTERNAL_PAUSE(
function(caller, onSuccess, onFail) { function(caller, onSuccess, onFail) {
@ -1966,7 +1948,7 @@ String.prototype.toDisplayedString = function(cache) {
var makeHashEq = function(lst) { var makeHashEq = function(lst) {
var newHash = new EqHashTable(); var newHash = new EqHashTable();
while ( !lst.isEmpty() ) { while ( !isEmpty(lst) ) {
newHash.hash.put(lst.first.first, lst.first.rest); newHash.hash.put(lst.first.first, lst.first.rest);
lst = lst.rest; lst = lst.rest;
} }
@ -1976,7 +1958,7 @@ String.prototype.toDisplayedString = function(cache) {
var makeHashEqual = function(lst) { var makeHashEqual = function(lst) {
var newHash = new EqualHashTable(); var newHash = new EqualHashTable();
while ( !lst.isEmpty() ) { while ( !isEmpty(lst) ) {
newHash.hash.put(lst.first.first, lst.first.rest); newHash.hash.put(lst.first.first, lst.first.rest);
lst = lst.rest; lst = lst.rest;
} }
@ -1985,12 +1967,16 @@ String.prototype.toDisplayedString = function(cache) {
var Color = makeStructureType('color', false, 3, 0, false, false); var Color = makeStructureType('color', false, 3, 0, false, false);
var ArityAtLeast = makeStructureType('arity-at-least', false, 1, 0, false, var ArityAtLeast = makeStructureType(
'arity-at-least', false, 1, 0, false,
function(args, name, k) { function(args, name, k) {
helpers.check(args[0], function(x) { return ( jsnums.isExact(x) && // helpers.check(args[0],
jsnums.isInteger(x) && // function(x) {
jsnums.greaterThanOrEqual(x, 0) ); }, // return ( jsnums.isExact(x) &&
name, 'exact non-negative integer', 1); // jsnums.isInteger(x) &&
// jsnums.greaterThanOrEqual(x, 0) ); },
// name,
// 'exact non-negative integer', 1);
return k(args); return k(args);
}); });
@ -2219,10 +2205,16 @@ String.prototype.toDisplayedString = function(cache) {
types.incompleteExn = function(constructor, msg, args) { return new IncompleteExn(constructor, msg, args); }; types.incompleteExn = function(constructor, msg, args) { return new IncompleteExn(constructor, msg, args); };
types.isIncompleteExn = function(x) { return x instanceof IncompleteExn; }; types.isIncompleteExn = function(x) { return x instanceof IncompleteExn; };
var Exn = makeStructureType('exn', false, 2, 0, false, var Exn = makeStructureType(
'exn',
false,
2,
0,
false,
function(args, name, k) { function(args, name, k) {
helpers.check(args[0], isString, name, 'string', 1); // helpers.check(args[0], isString, name, 'string', 1);
helpers.check(args[1], types.isContinuationMarkSet, name, 'continuation mark set', 2); // helpers.check(args[1], types.isContinuationMarkSet,
// name, 'continuation mark set', 2);
return k(args); return k(args);
}); });
types.exn = Exn.constructor; types.exn = Exn.constructor;
@ -2232,10 +2224,11 @@ String.prototype.toDisplayedString = function(cache) {
types.exnSetContMarks = function(exn, v) { Exn.mutator(exn, 1, v); }; types.exnSetContMarks = function(exn, v) { Exn.mutator(exn, 1, v); };
// (define-struct (exn:break exn) (continuation)) // (define-struct (exn:break exn) (continuation))
var ExnBreak = makeStructureType('exn:break', Exn, 1, 0, false, var ExnBreak = makeStructureType(
'exn:break', Exn, 1, 0, false,
function(args, name, k) { function(args, name, k) {
helpers.check(args[2], function(x) { return x instanceof ContinuationClosureValue; }, // helpers.check(args[2], function(x) { return x instanceof ContinuationClosureValue; },
name, 'continuation', 3); // name, 'continuation', 3);
return k(args); return k(args);
}); });
types.exnBreak = ExnBreak.constructor; types.exnBreak = ExnBreak.constructor;
@ -2271,7 +2264,7 @@ String.prototype.toDisplayedString = function(cache) {
var BigBangInfo = makeStructureType('bb-info', false, 2, 0, false, var BigBangInfo = makeStructureType('bb-info', false, 2, 0, false,
function(args, name, k) { function(args, name, k) {
//helpers.check(args[0], helpers.procArityContains(1), name, 'procedure (arity 1)', 1); //helpers.check(args[0], helpers.procArityContains(1), name, 'procedure (arity 1)', 1);
helpers.check(args[1], types.isJsValue, name, 'js-object', 2); //helpers.check(args[1], types.isJsValue, name, 'js-object', 2);
return k(args); return k(args);
}); });
types.BigBangInfo = BigBangInfo; types.BigBangInfo = BigBangInfo;