reducing dependence on single types.js module

This commit is contained in:
Danny Yoo 2011-07-06 16:49:28 -04:00
parent e20f984e26
commit cb99151753
15 changed files with 321 additions and 200 deletions

View File

@ -139,15 +139,15 @@
(define (floating-number->js a-num) (define (floating-number->js a-num)
(cond (cond
[(eqv? a-num -0.0) [(eqv? a-num -0.0)
"jsnums.negative_zero"] "RUNTIME.NEGATIVE_ZERO"]
[(eqv? a-num +inf.0) [(eqv? a-num +inf.0)
"jsnums.inf"] "RUNTIME.INF"]
[(eqv? a-num -inf.0) [(eqv? a-num -inf.0)
"jsnums.negative_inf"] "RUNTIME.NEGATIVE_INF"]
[(eqv? a-num +nan.0) [(eqv? a-num +nan.0)
"jsnums.nan"] "RUNTIME.NAN"]
[else [else
(string-append "jsnums.makeFloat(" (number->string a-num) ")")])) (string-append "RUNTIME.makeFloat(" (number->string a-num) ")")]))
;; FIXME: fix the type signature when typed-racket isn't breaking on ;; FIXME: fix the type signature when typed-racket isn't breaking on
;; (define-predicate ExactRational? (U Exact-Rational)) ;; (define-predicate ExactRational? (U Exact-Rational))
@ -156,7 +156,7 @@
(cond [(= (denominator a-num) 1) (cond [(= (denominator a-num) 1)
(string-append (integer->js (ensure-integer (numerator a-num))))] (string-append (integer->js (ensure-integer (numerator a-num))))]
[else [else
(string-append "jsnums.makeRational(" (string-append "RUNTIME.makeRational("
(integer->js (ensure-integer (numerator a-num))) (integer->js (ensure-integer (numerator a-num)))
", " ", "
(integer->js (ensure-integer (denominator a-num))) (integer->js (ensure-integer (denominator a-num)))
@ -179,7 +179,7 @@
(number->string an-int)] (number->string an-int)]
;; overflow case ;; overflow case
[else [else
(string-append "jsnums.makeBignum(" (string-append "RUNTIME.makeBignum("
(format "~s" (number->string an-int)) (format "~s" (number->string an-int))
")")])) ")")]))
@ -191,7 +191,7 @@
(floating-number->js a-num)] (floating-number->js a-num)]
[(complex? a-num) [(complex? a-num)
(string-append "jsnums.makeComplex(" (string-append "RUNTIME.makeComplex("
(assemble-numeric-constant (real-part a-num)) (assemble-numeric-constant (real-part a-num))
", " ", "
(assemble-numeric-constant (imag-part a-num)) (assemble-numeric-constant (imag-part a-num))
@ -318,7 +318,7 @@
[(natural? an-arity) [(natural? an-arity)
(number->string an-arity)] (number->string an-arity)]
[(ArityAtLeast? an-arity) [(ArityAtLeast? an-arity)
(format "(RUNTIME.arityAtLeast(~a))" (format "(RUNTIME.makeArityAtLeast(~a))"
(ArityAtLeast-value an-arity))] (ArityAtLeast-value an-arity))]
[(listof-atomic-arity? an-arity) [(listof-atomic-arity? an-arity)
(assemble-listof-assembled-values (assemble-listof-assembled-values
@ -328,7 +328,7 @@
[(natural? atomic-arity) [(natural? atomic-arity)
(number->string atomic-arity)] (number->string atomic-arity)]
[(ArityAtLeast? atomic-arity) [(ArityAtLeast? atomic-arity)
(format "(RUNTIME.arityAtLeast(~a))" (format "(RUNTIME.makeArityAtLeast(~a))"
(ArityAtLeast-value atomic-arity))])) (ArityAtLeast-value atomic-arity))]))
an-arity))])) an-arity))]))

View File

@ -31,43 +31,43 @@
(cond [(empty? checked-operands) (cond [(empty? checked-operands)
(assemble-numeric-constant 0)] (assemble-numeric-constant 0)]
[else [else
(assemble-binop-chain "jsnums.add" checked-operands)])] (assemble-binop-chain "plt.baselib.numbers.add" checked-operands)])]
[(-) [(-)
(cond [(empty? (rest checked-operands)) (cond [(empty? (rest checked-operands))
(assemble-binop-chain "jsnums.subtract" (cons "0" checked-operands))] (assemble-binop-chain "plt.baselib.numbers.subtract" (cons "0" checked-operands))]
[else [else
(assemble-binop-chain "jsnums.subtract" checked-operands)])] (assemble-binop-chain "plt.baselib.numbers.subtract" checked-operands)])]
[(*) [(*)
(cond [(empty? checked-operands) (cond [(empty? checked-operands)
(assemble-numeric-constant 1)] (assemble-numeric-constant 1)]
[else [else
(assemble-binop-chain "jsnums.multiply" checked-operands)])] (assemble-binop-chain "plt.baselib.numbers.multiply" checked-operands)])]
[(/) [(/)
(assemble-binop-chain "jsnums.divide" checked-operands)] (assemble-binop-chain "plt.baselib.numbers.divide" checked-operands)]
[(add1) [(add1)
(assemble-binop-chain "jsnums.add" (cons "1" checked-operands))] (assemble-binop-chain "plt.baselib.numbers.add" (cons "1" checked-operands))]
[(sub1) [(sub1)
(assemble-binop-chain "jsnums.subtract" (append checked-operands (list "1")))] (assemble-binop-chain "plt.baselib.numbers.subtract" (append checked-operands (list "1")))]
[(<) [(<)
(assemble-boolean-chain "jsnums.lessThan" checked-operands)] (assemble-boolean-chain "plt.baselib.numbers.lessThan" checked-operands)]
[(<=) [(<=)
(assemble-boolean-chain "jsnums.lessThanOrEqual" checked-operands)] (assemble-boolean-chain "plt.baselib.numbers.lessThanOrEqual" checked-operands)]
[(=) [(=)
(assemble-boolean-chain "jsnums.equals" checked-operands)] (assemble-boolean-chain "plt.baselib.numbers.equals" checked-operands)]
[(>) [(>)
(assemble-boolean-chain "jsnums.greaterThan" checked-operands)] (assemble-boolean-chain "plt.baselib.numbers.greaterThan" checked-operands)]
[(>=) [(>=)
(assemble-boolean-chain "jsnums.greaterThanOrEqual" checked-operands)] (assemble-boolean-chain "plt.baselib.numbers.greaterThanOrEqual" checked-operands)]
[(cons) [(cons)
(format "RUNTIME.makePair(~a, ~a)" (format "RUNTIME.makePair(~a, ~a)"
@ -108,10 +108,10 @@
(cons (string-append rator "(" (first rands) ", " (second rands) ")") (cons (string-append rator "(" (first rands) ", " (second rands) ")")
(rest (rest rands))))])) (rest (rest rands))))]))
(check-equal? (assemble-binop-chain "jsnums.add" '("3" "4" "5")) (check-equal? (assemble-binop-chain "plt.baselib.numbers.add" '("3" "4" "5"))
"jsnums.add(jsnums.add(3, 4), 5)") "plt.baselib.numbers.add(plt.baselib.numbers.add(3, 4), 5)")
(check-equal? (assemble-binop-chain "jsnums.subtract" '("0" "42")) (check-equal? (assemble-binop-chain "plt.baselib.numbers.subtract" '("0" "42"))
"jsnums.subtract(0, 42)") "plt.baselib.numbers.subtract(0, 42)")
@ -146,7 +146,7 @@
(let: ([test-string : String (let: ([test-string : String
(case domain (case domain
[(number) [(number)
(format "jsnums.isSchemeNumber(~a)" (format "RUNTIME.isNumber(~a)"
operand-string)] operand-string)]
[(string) [(string)
(format "(typeof(~a) === 'string')" (format "(typeof(~a) === 'string')"

View File

@ -48,6 +48,7 @@
baselib-format.js baselib-format.js
baselib-constants.js baselib-constants.js
baselib-numbers.js
baselib-lists.js baselib-lists.js
baselib-vectors.js baselib-vectors.js
baselib-chars.js baselib-chars.js

View File

@ -54,10 +54,7 @@
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
exports.ArityAtLeast = ArityAtLeast; exports.ArityAtLeast = ArityAtLeast;
exports.arityAtLeast = function() { exports.makeArityAtLeast = ArityAtLeast.constructor;
var result = ArityAtLeast.constructor.apply(null, arguments);
return result;
};
exports.isArityAtLeast = isArityAtLeast; exports.isArityAtLeast = isArityAtLeast;
exports.isArityMatching = isArityMatching; exports.isArityMatching = isArityMatching;
exports.arityAtLeastValue = arityAtLeastValue; exports.arityAtLeastValue = arityAtLeastValue;

View File

@ -9,8 +9,8 @@
var equals = function(x, y, aUnionFind) { var equals = function(x, y, aUnionFind) {
if (x === y) { return true; } if (x === y) { return true; }
if (jsnums.isSchemeNumber(x) && jsnums.isSchemeNumber(y)) { if (plt.baselib.numbers.isNumber(x) && plt.baselib.numbers.isNumber(y)) {
return jsnums.eqv(x, y); return plt.baselib.numbers.eqv(x, y);
} }
if (baselib.strings.isString(x) && baselib.strings.isString(y)) { if (baselib.strings.isString(x) && baselib.strings.isString(y)) {

View File

@ -200,7 +200,7 @@
params = params || new ToDomNodeParameters({'mode' : 'display'}); params = params || new ToDomNodeParameters({'mode' : 'display'});
} }
if (jsnums.isSchemeNumber(x)) { if (plt.baselib.numbers.isSchemeNumber(x)) {
var node = numberToDomNode(x, params); var node = numberToDomNode(x, params);
$(node).addClass("number"); $(node).addClass("number");
return node; return node;
@ -291,14 +291,14 @@
// Given a jsnum, produces a dom-node representation. // Given a jsnum, produces a dom-node representation.
var numberToDomNode = function(n, params) { var numberToDomNode = function(n, params) {
var node; var node;
if (jsnums.isExact(n)) { if (plt.baselib.numbers.isExact(n)) {
if (jsnums.isInteger(n)) { if (plt.baselib.numbers.isInteger(n)) {
node = document.createElement("span"); node = document.createElement("span");
node.appendChild(document.createTextNode(n.toString())); node.appendChild(document.createTextNode(n.toString()));
return node; return node;
} else if (jsnums.isRational(n)) { } else if (plt.baselib.numbers.isRational(n)) {
return rationalToDomNode(n); return rationalToDomNode(n);
} else if (jsnums.isComplex(n)) { } else if (plt.baselib.numbers.isComplex(n)) {
node = document.createElement("span"); node = document.createElement("span");
node.appendChild(document.createTextNode(n.toString())); node.appendChild(document.createTextNode(n.toString()));
return node; return node;
@ -317,8 +317,8 @@
// rationalToDomNode: rational -> dom-node // rationalToDomNode: rational -> dom-node
var rationalToDomNode = function(n) { var rationalToDomNode = function(n) {
var repeatingDecimalNode = document.createElement("span"); var repeatingDecimalNode = document.createElement("span");
var chunks = jsnums.toRepeatingDecimal(jsnums.numerator(n), var chunks = plt.baselib.numbers.toRepeatingDecimal(plt.baselib.numbers.numerator(n),
jsnums.denominator(n), plt.baselib.numbers.denominator(n),
{limit: 25}); {limit: 25});
repeatingDecimalNode.appendChild(document.createTextNode(chunks[0] + '.')) repeatingDecimalNode.appendChild(document.createTextNode(chunks[0] + '.'))
repeatingDecimalNode.appendChild(document.createTextNode(chunks[1])); repeatingDecimalNode.appendChild(document.createTextNode(chunks[1]));
@ -335,9 +335,9 @@
var fractionalNode = document.createElement("span"); var fractionalNode = document.createElement("span");
var numeratorNode = document.createElement("sup"); var numeratorNode = document.createElement("sup");
numeratorNode.appendChild(document.createTextNode(String(jsnums.numerator(n)))); numeratorNode.appendChild(document.createTextNode(String(plt.baselib.numbers.numerator(n))));
var denominatorNode = document.createElement("sub"); var denominatorNode = document.createElement("sub");
denominatorNode.appendChild(document.createTextNode(String(jsnums.denominator(n)))); denominatorNode.appendChild(document.createTextNode(String(plt.baselib.numbers.denominator(n))));
fractionalNode.appendChild(numeratorNode); fractionalNode.appendChild(numeratorNode);
fractionalNode.appendChild(document.createTextNode("/")); fractionalNode.appendChild(document.createTextNode("/"));
fractionalNode.appendChild(denominatorNode); fractionalNode.appendChild(denominatorNode);

View File

@ -161,6 +161,10 @@
var isHash = function(x) {
return (x instanceof EqHashTable ||
x instanceof EqualHashTable);
};
@ -178,7 +182,7 @@
//////////////////////////////////////////////////////////////////////
exports.getEqHashCode = getEqHashCode; exports.getEqHashCode = getEqHashCode;
exports.makeEqHashCode = makeEqHashCode; exports.makeEqHashCode = makeEqHashCode;
@ -187,7 +191,7 @@
exports.EqualHashTable = EqualHashTable; exports.EqualHashTable = EqualHashTable;
exports.EqHashTable = EqHashTable; exports.EqHashTable = EqHashTable;
exports.isHash = isHash;
})(this['plt'].baselib); })(this['plt'].baselib);

View File

@ -37,9 +37,9 @@
// Cons Pairs // Cons Pairs
var Cons = function(f, r) { var Cons = function(first, rest) {
this.first = f; this.first = first;
this.rest = r; this.rest = rest;
}; };
Cons.prototype.reverse = function() { Cons.prototype.reverse = function() {
@ -52,8 +52,8 @@
return ret; return ret;
}; };
Cons.makeInstance = function(f, r) { Cons.makeInstance = function(first, rest) {
return new Cons(f, r); return new Cons(first, rest);
}; };
// FIXME: can we reduce the recursion on this? // FIXME: can we reduce the recursion on this?
@ -149,10 +149,18 @@
}; };
var isPair = function(x) { return x instanceof Cons; };
var makePair = Cons.makeInstance;
//////////////////////////////////////////////////////////////////////
exports.EMPTY = Empty.EMPTY; exports.EMPTY = Empty.EMPTY;
exports.Empty = Empty; exports.Empty = Empty;
exports.Cons = Cons; exports.Cons = Cons;
exports.isPair = isPair;
exports.makePair = makePair;

View File

@ -0,0 +1,48 @@
// Numbers.
(function(baselib) {
var exports = {};
baselib.numbers = exports;
var isNumber = jsnums.isSchemeNumber;
var isReal = jsnums.isReal;
var isRational = jsnums.isRational;
var isComplex = isNumber;
var isInteger = jsnums.isInteger;
var isNatural = function(x) {
return (jsnums.isExact(x) && isInteger(x)
&& jsnums.greaterThanOrEqual(x, 0));
};
var isNonNegativeReal = function(x) {
return isReal(x) && jsnums.greaterThanOrEqual(x, 0);
};
//////////////////////////////////////////////////////////////////////
// Exports
// We first re-export everything in jsnums.
for (var prop in jsnums) {
if (jsnums.hasOwnProperty(prop)) {
exports[prop] = jsnums[prop];
}
}
exports.isNumber = jsnums.isSchemeNumber;
exports.isReal = isReal;
exports.isRational = isRational;
exports.isComplex = isComplex;
exports.isInteger = isInteger;
exports.isNatural = isNatural;
exports.isNonNegativeReal = isNonNegativeReal;
})(this['plt'].baselib);

View File

@ -1,4 +1,4 @@
// Exceptions // Placeholders
(function(baselib) { (function(baselib) {
var exports = {}; var exports = {};
@ -43,7 +43,16 @@
}; };
var isPlaceholder = function(x) {
return x instanceof Placeholder;
};
//////////////////////////////////////////////////////////////////////
exports.Placeholder = Placeholder; exports.Placeholder = Placeholder;
exports.isPlaceholder = isPlaceholder;
})(this['plt'].baselib); })(this['plt'].baselib);

View File

@ -9,17 +9,17 @@
return objectHash.get(x); return objectHash.get(x);
} }
if (types.isPair(x)) { if (plt.baselib.lists.isPair(x)) {
var consPair = types.cons(x.first, x.rest); var consPair = plt.baselib.lists.makePair(x.first, x.rest);
objectHash.put(x, consPair); objectHash.put(x, consPair);
consPair.f = readerGraph(x.first, objectHash, n+1); consPair.first = readerGraph(x.first, objectHash, n+1);
consPair.r = readerGraph(x.rest, objectHash, n+1); consPair.rest = readerGraph(x.rest, objectHash, n+1);
return consPair; return consPair;
} }
if (types.isVector(x)) { if (plt.baselib.vectors.isVector(x)) {
var len = x.length(); var len = x.length();
var aVector = types.vector(len, x.elts); var aVector = plt.baselib.vectors.makeVector(len, x.elts);
objectHash.put(x, aVector); objectHash.put(x, aVector);
for (var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
aVector.elts[i] = readerGraph(aVector.elts[i], objectHash, n+1); aVector.elts[i] = readerGraph(aVector.elts[i], objectHash, n+1);
@ -27,18 +27,18 @@
return aVector; return aVector;
} }
if (types.isBox(x)) { if (plt.baselib.boxes.isBox(x)) {
var aBox = types.box(x.ref()); var aBox = plt.baselib.boxes.makeBox(x.ref());
objectHash.put(x, aBox); objectHash.put(x, aBox);
aBox.val = readerGraph(x.ref(), objectHash, n+1); aBox.val = readerGraph(x.ref(), objectHash, n+1);
return aBox; return aBox;
} }
if (types.isHash(x)) { if (plt.baselib.hashes.isHash(x)) {
throw new Error("make-reader-graph of hash not implemented yet"); throw new Error("make-reader-graph of hash not implemented yet");
} }
if (types.isStruct(x)) { if (plt.baselib.structs.isStruct(x)) {
var aStruct = baselib.clone(x); var aStruct = baselib.clone(x);
objectHash.put(x, aStruct); objectHash.put(x, aStruct);
for(var i = 0 ;i < x._fields.length; i++) { for(var i = 0 ;i < x._fields.length; i++) {
@ -47,7 +47,7 @@
return aStruct; return aStruct;
} }
if (types.isPlaceholder(x)) { if (plt.baselib.placeholders.isPlaceholder(x)) {
return readerGraph(x.ref(), objectHash, n+1); return readerGraph(x.ref(), objectHash, n+1);
} }

View File

@ -1,8 +1,8 @@
// Structure types // Structure types
(function(baselib) { (function(baselib) {
var structs = {}; var exports = {};
baselib.structs = structs; baselib.structs = exports;
@ -258,6 +258,7 @@
var isStruct = function(x) { return x instanceof Struct; };
@ -273,18 +274,22 @@
structs.StructType = StructType;
structs.Struct = Struct;
// structs.StructProc = StructProc;
// structs.StructConstructorProc = StructConstructorProc; exports.StructType = StructType;
// structs.StructPredicateProc = StructPredicateProc; exports.Struct = Struct;
// structs.StructAccessorProc = StructAccessorProc; exports.makeStructureType = makeStructureType;
// structs.StructMutatorProc = StructMutatorProc; exports.isStruct = isStruct;
// exports.StructProc = StructProc;
// exports.StructConstructorProc = StructConstructorProc;
// exports.StructPredicateProc = StructPredicateProc;
// exports.StructAccessorProc = StructAccessorProc;
// exports.StructMutatorProc = StructMutatorProc;
structs.makeStructureType = makeStructureType;

View File

@ -93,7 +93,26 @@
}; };
var isVector = function(x) { return x instanceof Vector; };
var makeVector = function() {
return Vector.makeInstance(arguments.length, arguments);
};
var makeVectorImmutable = function() {
var v = Vector.makeInstance(arguments.length, arguments);
v.mutable = false;
return v;
};
//////////////////////////////////////////////////////////////////////
exports.Vector = Vector; exports.Vector = Vector;
exports.isVector = isVector;
exports.makeVector = makeVector;
exports.makeVectorImmutable = makeVectorImmutable;
})(this['plt'].baselib); })(this['plt'].baselib);

View File

@ -24,8 +24,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
// We try to isolate the effect of external modules: all the identifiers we // We try to isolate the effect of external modules: all the identifiers we
// pull from external modules should be listed here, and should otherwise not // pull from external modules should be listed here, and should otherwise not
// show up outside this section! // show up outside this section!
var isNumber = jsnums.isSchemeNumber; var isNumber = plt.baselib.numbers.isNumber;
var isNatural = types.isNatural; var isNatural = plt.baselib.numbers.isNatural;
var isReal = plt.baselib.numbers.isReal;
var isPair = types.isPair; var isPair = types.isPair;
var isList = types.isList; var isList = types.isList;
var isVector = types.isVector; var isVector = types.isVector;
@ -37,6 +38,18 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var VOID = plt.baselib.constants.VOID_VALUE; var VOID = plt.baselib.constants.VOID_VALUE;
var EOF = plt.baselib.constants.EOF_VALUE; var EOF = plt.baselib.constants.EOF_VALUE;
var NEGATIVE_ZERO = plt.baselib.numbers.negative_zero;
var INF = plt.baselib.numbers.inf;
var NEGATIVE_INF = plt.baselib.numbers.negative_inf;
var NAN = plt.baselib.numbers.nan;
var makeFloat = plt.baselib.numbers.makeFloat;
var makeRational = plt.baselib.numbers.makeRational;
var makeBignum = plt.baselib.numbers.makeBignum;
var makeComplex = plt.baselib.numbers.makeComplex;
var makeVector = types.vector; var makeVector = types.vector;
var makeList = types.list; var makeList = types.list;
var makePair = types.pair; var makePair = types.pair;
@ -59,9 +72,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
//////////////////////////////////////////////////////////////////////] //////////////////////////////////////////////////////////////////////]
var isNonNegativeReal = function(x) { var isNonNegativeReal = plt.baselib.numbers.isNonNegativeReal;
return jsnums.isReal(x) && jsnums.greaterThanOrEqual(x, 0);
};
@ -564,8 +576,8 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveConstant('pi', jsnums.pi); installPrimitiveConstant('pi', plt.baselib.numbers.pi);
installPrimitiveConstant('e', jsnums.e); installPrimitiveConstant('e', plt.baselib.numbers.e);
installPrimitiveConstant('null', NULL); installPrimitiveConstant('null', NULL);
@ -628,7 +640,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'format', 'format',
plt.baselib.arity.arityAtLeast(1), plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) { function(MACHINE) {
var args = [], i, formatString; var args = [], i, formatString;
testArgument(MACHINE, testArgument(MACHINE,
@ -648,7 +660,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'printf', 'printf',
plt.baselib.arity.arityAtLeast(1), plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) { function(MACHINE) {
var args = [], i, formatString; var args = [], i, formatString;
testArgument(MACHINE, testArgument(MACHINE,
@ -670,7 +682,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'fprintf', 'fprintf',
plt.baselib.arity.arityAtLeast(2), plt.baselib.arity.makeArityAtLeast(2),
function(MACHINE) { function(MACHINE) {
var args = [], i, formatString; var args = [], i, formatString;
testArgument(MACHINE, testArgument(MACHINE,
@ -731,7 +743,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'=', '=',
plt.baselib.arity.arityAtLeast(2), plt.baselib.arity.makeArityAtLeast(2),
function(MACHINE) { function(MACHINE) {
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
testArgument(MACHINE, 'number', isNumber, firstArg, 0, '='); testArgument(MACHINE, 'number', isNumber, firstArg, 0, '=');
@ -742,8 +754,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'='); '=');
if (! (jsnums.equals(MACHINE.env[MACHINE.env.length - 1 - i], if (! (plt.baselib.numbers.equals(
MACHINE.env[MACHINE.env.length - 1 - i - 1]))) { MACHINE.env[MACHINE.env.length - 1 - i],
MACHINE.env[MACHINE.env.length - 1 - i - 1]))) {
return false; return false;
} }
} }
@ -758,13 +771,13 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'=~'); '=~');
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'=~'); '=~');
@ -777,7 +790,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var x = MACHINE.env[MACHINE.env.length-1]; var x = MACHINE.env[MACHINE.env.length-1];
var y = MACHINE.env[MACHINE.env.length-2]; var y = MACHINE.env[MACHINE.env.length-2];
var range = MACHINE.env[MACHINE.env.length-3]; var range = MACHINE.env[MACHINE.env.length-3];
return jsnums.lessThanOrEqual(jsnums.abs(jsnums.subtract(x, y)), range); return plt.baselib.numbers.lessThanOrEqual(plt.baselib.numbers.abs(plt.baselib.numbers.subtract(x, y)), range);
}); });
@ -785,7 +798,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'<', '<',
plt.baselib.arity.arityAtLeast(2), plt.baselib.arity.makeArityAtLeast(2),
function(MACHINE) { function(MACHINE) {
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
testArgument(MACHINE, testArgument(MACHINE,
@ -797,7 +810,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'<'); '<');
if (! (jsnums.lessThan(MACHINE.env[MACHINE.env.length - 1 - i], if (! (plt.baselib.numbers.lessThan(MACHINE.env[MACHINE.env.length - 1 - i],
MACHINE.env[MACHINE.env.length - 1 - i - 1]))) { MACHINE.env[MACHINE.env.length - 1 - i - 1]))) {
return false; return false;
} }
@ -808,7 +821,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'>', '>',
plt.baselib.arity.arityAtLeast(2), plt.baselib.arity.makeArityAtLeast(2),
function(MACHINE) { function(MACHINE) {
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
testArgument(MACHINE, testArgument(MACHINE,
@ -820,7 +833,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'>'); '>');
if (! (jsnums.greaterThan(MACHINE.env[MACHINE.env.length - 1 - i], if (! (plt.baselib.numbers.greaterThan(MACHINE.env[MACHINE.env.length - 1 - i],
MACHINE.env[MACHINE.env.length - 1 - i - 1]))) { MACHINE.env[MACHINE.env.length - 1 - i - 1]))) {
return false; return false;
} }
@ -830,7 +843,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'<=', '<=',
plt.baselib.arity.arityAtLeast(2), plt.baselib.arity.makeArityAtLeast(2),
function(MACHINE) { function(MACHINE) {
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
testArgument(MACHINE, testArgument(MACHINE,
@ -842,7 +855,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'<='); '<=');
if (! (jsnums.lessThanOrEqual(MACHINE.env[MACHINE.env.length - 1 - i], if (! (plt.baselib.numbers.lessThanOrEqual(MACHINE.env[MACHINE.env.length - 1 - i],
MACHINE.env[MACHINE.env.length - 1 - i - 1]))) { MACHINE.env[MACHINE.env.length - 1 - i - 1]))) {
return false; return false;
} }
@ -853,7 +866,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'>=', '>=',
plt.baselib.arity.arityAtLeast(2), plt.baselib.arity.makeArityAtLeast(2),
function(MACHINE) { function(MACHINE) {
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
testArgument(MACHINE, testArgument(MACHINE,
@ -865,7 +878,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'>='); '>=');
if (! (jsnums.greaterThanOrEqual(MACHINE.env[MACHINE.env.length - 1 - i], if (! (plt.baselib.numbers.greaterThanOrEqual(MACHINE.env[MACHINE.env.length - 1 - i],
MACHINE.env[MACHINE.env.length - 1 - i - 1]))) { MACHINE.env[MACHINE.env.length - 1 - i - 1]))) {
return false; return false;
} }
@ -876,7 +889,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'+', '+',
plt.baselib.arity.arityAtLeast(0), plt.baselib.arity.makeArityAtLeast(0),
function(MACHINE) { function(MACHINE) {
var result = 0; var result = 0;
var i = 0; var i = 0;
@ -887,7 +900,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'+'); '+');
result = jsnums.add(result, MACHINE.env[MACHINE.env.length - 1 - i]); result = plt.baselib.numbers.add(result, MACHINE.env[MACHINE.env.length - 1 - i]);
}; };
return result; return result;
}); });
@ -895,7 +908,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'*', '*',
plt.baselib.arity.arityAtLeast(0), plt.baselib.arity.makeArityAtLeast(0),
function(MACHINE) { function(MACHINE) {
var result = 1; var result = 1;
var i = 0; var i = 0;
@ -906,14 +919,14 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'*'); '*');
result = jsnums.multiply(result, MACHINE.env[MACHINE.env.length - 1 - i]); result = plt.baselib.numbers.multiply(result, MACHINE.env[MACHINE.env.length - 1 - i]);
} }
return result; return result;
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
'-', '-',
plt.baselib.arity.arityAtLeast(1), plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) { function(MACHINE) {
if (MACHINE.argcount === 1) { if (MACHINE.argcount === 1) {
testArgument(MACHINE, testArgument(MACHINE,
@ -922,7 +935,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'-'); '-');
return jsnums.subtract(0, MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.subtract(0, MACHINE.env[MACHINE.env.length-1]);
} }
var result = MACHINE.env[MACHINE.env.length - 1]; var result = MACHINE.env[MACHINE.env.length - 1];
for (var i = 1; i < MACHINE.argcount; i++) { for (var i = 1; i < MACHINE.argcount; i++) {
@ -932,14 +945,14 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1-i], MACHINE.env[MACHINE.env.length-1-i],
i, i,
'-'); '-');
result = jsnums.subtract(result, MACHINE.env[MACHINE.env.length - 1 - i]); result = plt.baselib.numbers.subtract(result, MACHINE.env[MACHINE.env.length - 1 - i]);
} }
return result; return result;
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
'/', '/',
plt.baselib.arity.arityAtLeast(1), plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'number', 'number',
@ -955,7 +968,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1-i], MACHINE.env[MACHINE.env.length-1-i],
i, i,
'/'); '/');
result = jsnums.divide(result, MACHINE.env[MACHINE.env.length - 1 - i]); result = plt.baselib.numbers.divide(result, MACHINE.env[MACHINE.env.length - 1 - i]);
} }
return result; return result;
}); });
@ -972,7 +985,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
0, 0,
'add1'); 'add1');
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
return jsnums.add(firstArg, 1); return plt.baselib.numbers.add(firstArg, 1);
}); });
@ -987,7 +1000,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
0, 0,
'sub1'); 'sub1');
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
return jsnums.subtract(firstArg, 1); return plt.baselib.numbers.subtract(firstArg, 1);
}); });
@ -996,7 +1009,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
1, 1,
function(MACHINE) { function(MACHINE) {
var firstArg = MACHINE.env[MACHINE.env.length-1]; var firstArg = MACHINE.env[MACHINE.env.length-1];
return jsnums.equals(firstArg, 0); return plt.baselib.numbers.equals(firstArg, 0);
}); });
@ -1012,7 +1025,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'list', 'list',
plt.baselib.arity.arityAtLeast(0), plt.baselib.arity.makeArityAtLeast(0),
function(MACHINE) { function(MACHINE) {
var result = NULL; var result = NULL;
for (var i = 0; i < MACHINE.argcount; i++) { for (var i = 0; i < MACHINE.argcount; i++) {
@ -1112,7 +1125,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'vector', 'vector',
plt.baselib.arity.arityAtLeast(0), plt.baselib.arity.makeArityAtLeast(0),
function(MACHINE) { function(MACHINE) {
var i; var i;
var result = []; var result = [];
@ -1191,7 +1204,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
1, 1,
'vector-set!'); 'vector-set!');
var elts = MACHINE.env[MACHINE.env.length-1].elts; var elts = MACHINE.env[MACHINE.env.length-1].elts;
var index = jsnums.toFixnum(MACHINE.env[MACHINE.env.length-2]); var index = plt.baselib.numbers.toFixnum(MACHINE.env[MACHINE.env.length-2]);
var val = MACHINE.env[MACHINE.env.length-3]; var val = MACHINE.env[MACHINE.env.length-3];
elts[index] = val; elts[index] = val;
return VOID; return VOID;
@ -1226,7 +1239,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
if (MACHINE.argcount == 2) { if (MACHINE.argcount == 2) {
value = MACHINE.env[MACHINE.env.length - 2]; value = MACHINE.env[MACHINE.env.length - 2];
} }
var length = jsnums.toFixnum(MACHINE.env[MACHINE.env.length-1]); var length = plt.baselib.numbers.toFixnum(MACHINE.env[MACHINE.env.length-1]);
var arr = []; var arr = [];
for(var i = 0; i < length; i++) { for(var i = 0; i < length; i++) {
arr[i] = value; arr[i] = value;
@ -1254,7 +1267,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'string-append', 'string-append',
plt.baselib.arity.arityAtLeast(0), plt.baselib.arity.makeArityAtLeast(0),
function(MACHINE) { function(MACHINE) {
var buffer = []; var buffer = [];
var i; var i;
@ -1302,7 +1315,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'void', 'void',
plt.baselib.arity.arityAtLeast(0), plt.baselib.arity.makeArityAtLeast(0),
function(MACHINE) { function(MACHINE) {
return VOID; return VOID;
}); });
@ -1380,7 +1393,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'abs'); 'abs');
return jsnums.abs(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.abs(MACHINE.env[MACHINE.env.length-1]);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
@ -1393,7 +1406,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'acos'); 'acos');
return jsnums.acos(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.acos(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1407,7 +1420,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'asin'); 'asin');
return jsnums.asin(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.asin(MACHINE.env[MACHINE.env.length-1]);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
@ -1420,7 +1433,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'sin'); 'sin');
return jsnums.sin(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.sin(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1435,7 +1448,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'sinh'); 'sinh');
return jsnums.sinh(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.sinh(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1449,7 +1462,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'tan'); 'tan');
return jsnums.tan(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.tan(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1465,7 +1478,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'atan'); 'atan');
return jsnums.atan(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.atan(MACHINE.env[MACHINE.env.length - 1]);
} else { } else {
testArgument(MACHINE, testArgument(MACHINE,
'number', 'number',
@ -1479,9 +1492,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'atan'); 'atan');
return jsnums.makeFloat( return plt.baselib.numbers.makeFloat(
Math.atan2(jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 1]), Math.atan2(plt.baselib.numbers.toFixnum(MACHINE.env[MACHINE.env.length - 1]),
jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 2]))); plt.baselib.numbers.toFixnum(MACHINE.env[MACHINE.env.length - 2])));
} }
}); });
@ -1496,7 +1509,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'angle'); 'angle');
return jsnums.angle(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.angle(MACHINE.env[MACHINE.env.length-1]);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
@ -1509,7 +1522,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'magnitude'); 'magnitude');
return jsnums.magnitude(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.magnitude(MACHINE.env[MACHINE.env.length-1]);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
@ -1522,7 +1535,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'conjugate'); 'conjugate');
return jsnums.conjugate(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.conjugate(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1538,7 +1551,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'cos'); 'cos');
return jsnums.cos(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.cos(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1552,18 +1565,18 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'cosh'); 'cosh');
return jsnums.cosh(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.cosh(MACHINE.env[MACHINE.env.length-1]);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
'gcd', 'gcd',
plt.baselib.arity.arityAtLeast(1), plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) { function(MACHINE) {
var args = [], i, x; var args = [], i, x;
for (i = 0; i < MACHINE.argcount; i++) { for (i = 0; i < MACHINE.argcount; i++) {
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'gcd'); 'gcd');
@ -1571,18 +1584,18 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
} }
x = args.shift(); x = args.shift();
return jsnums.gcd(x, args); return plt.baselib.numbers.gcd(x, args);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
'lcm', 'lcm',
plt.baselib.arity.arityAtLeast(1), plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) { function(MACHINE) {
var args = [], i, x; var args = [], i, x;
for (i = 0; i < MACHINE.argcount; i++) { for (i = 0; i < MACHINE.argcount; i++) {
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 1 - i], MACHINE.env[MACHINE.env.length - 1 - i],
i, i,
'lcm'); 'lcm');
@ -1590,7 +1603,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
} }
x = args.shift(); x = args.shift();
return jsnums.lcm(x, args); return plt.baselib.numbers.lcm(x, args);
}); });
@ -1606,7 +1619,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'exp'); 'exp');
return jsnums.exp(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.exp(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1626,7 +1639,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'expt'); 'expt');
return jsnums.expt(MACHINE.env[MACHINE.env.length - 1], return plt.baselib.numbers.expt(MACHINE.env[MACHINE.env.length - 1],
MACHINE.env[MACHINE.env.length - 2]); MACHINE.env[MACHINE.env.length - 2]);
}); });
@ -1641,7 +1654,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'exact?'); 'exact?');
return jsnums.isExact(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.isExact(MACHINE.env[MACHINE.env.length - 1]);
}); });
@ -1655,7 +1668,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'imag-part'); 'imag-part');
return jsnums.imaginaryPart(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.imaginaryPart(MACHINE.env[MACHINE.env.length - 1]);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
@ -1668,7 +1681,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'real-part'); 'real-part');
return jsnums.realPart(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.realPart(MACHINE.env[MACHINE.env.length - 1]);
}); });
@ -1679,17 +1692,17 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'make-polar'); 'make-polar');
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'make-polar'); 'make-polar');
return jsnums.makeComplexPolar(MACHINE.env[MACHINE.env.length - 1], return plt.baselib.numbers.makeComplexPolar(MACHINE.env[MACHINE.env.length - 1],
MACHINE.env[MACHINE.env.length - 2]); MACHINE.env[MACHINE.env.length - 2]);
}); });
@ -1700,17 +1713,17 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'make-rectangular'); 'make-rectangular');
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'make-rectangular'); 'make-rectangular');
return jsnums.makeComplex(MACHINE.env[MACHINE.env.length - 1], return plt.baselib.numbers.makeComplex(MACHINE.env[MACHINE.env.length - 1],
MACHINE.env[MACHINE.env.length - 2]); MACHINE.env[MACHINE.env.length - 2]);
}); });
@ -1720,17 +1733,17 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'modulo'); 'modulo');
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'modulo'); 'modulo');
return jsnums.modulo(MACHINE.env[MACHINE.env.length - 1], return plt.baselib.numbers.modulo(MACHINE.env[MACHINE.env.length - 1],
MACHINE.env[MACHINE.env.length - 2]); MACHINE.env[MACHINE.env.length - 2]);
}); });
@ -1741,17 +1754,17 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'remainder'); 'remainder');
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'remainder'); 'remainder');
return jsnums.remainder(MACHINE.env[MACHINE.env.length - 1], return plt.baselib.numbers.remainder(MACHINE.env[MACHINE.env.length - 1],
MACHINE.env[MACHINE.env.length - 2]); MACHINE.env[MACHINE.env.length - 2]);
}); });
@ -1762,17 +1775,17 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'quotient'); 'quotient');
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length - 2], MACHINE.env[MACHINE.env.length - 2],
1, 1,
'quotient'); 'quotient');
return jsnums.quotient(MACHINE.env[MACHINE.env.length - 1], return plt.baselib.numbers.quotient(MACHINE.env[MACHINE.env.length - 1],
MACHINE.env[MACHINE.env.length - 2]); MACHINE.env[MACHINE.env.length - 2]);
}); });
@ -1784,11 +1797,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'floor'); 'floor');
return jsnums.floor(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.floor(MACHINE.env[MACHINE.env.length - 1]);
}); });
@ -1798,11 +1811,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'ceiling'); 'ceiling');
return jsnums.ceiling(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.ceiling(MACHINE.env[MACHINE.env.length - 1]);
}); });
@ -1812,11 +1825,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'round'); 'round');
return jsnums.round(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.round(MACHINE.env[MACHINE.env.length - 1]);
}); });
@ -1826,14 +1839,14 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'real', 'real',
jsnums.isReal, isReal,
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
0, 0,
'truncate'); 'truncate');
if (jsnums.lessThan(MACHINE.env[MACHINE.env.length - 1], 0)) { if (plt.baselib.numbers.lessThan(MACHINE.env[MACHINE.env.length - 1], 0)) {
return jsnums.ceiling(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.ceiling(MACHINE.env[MACHINE.env.length - 1]);
} else { } else {
return jsnums.floor(MACHINE.env[MACHINE.env.length - 1]); return plt.baselib.numbers.floor(MACHINE.env[MACHINE.env.length - 1]);
} }
}); });
@ -1844,11 +1857,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'rational', 'rational',
jsnums.isRational, plt.baselib.numbers.isRational,
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'numerator'); 'numerator');
return jsnums.numerator(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.numerator(MACHINE.env[MACHINE.env.length-1]);
}); });
installPrimitiveProcedure( installPrimitiveProcedure(
@ -1857,11 +1870,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'rational', 'rational',
jsnums.isRational, plt.baselib.numbers.isRational,
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'denominator'); 'denominator');
return jsnums.denominator(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.denominator(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1875,7 +1888,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'log'); 'log');
return jsnums.log(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.log(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1889,7 +1902,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'sqr'); 'sqr');
return jsnums.sqr(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.sqr(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1905,7 +1918,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'sqrt'); 'sqrt');
return jsnums.sqrt(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.sqrt(MACHINE.env[MACHINE.env.length-1]);
}); });
@ -1917,28 +1930,28 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'integer-sqrt'); 'integer-sqrt');
return jsnums.integerSqrt(MACHINE.env[MACHINE.env.length-1]); return plt.baselib.numbers.integerSqrt(MACHINE.env[MACHINE.env.length-1]);
}); });
// rawSgn: number -> number // rawSgn: number -> number
var rawSgn = function(x) { var rawSgn = function(x) {
if (jsnums.isInexact(x)) { if (plt.baselib.numbers.isInexact(x)) {
if ( jsnums.greaterThan(x, 0) ) { if ( plt.baselib.numbers.greaterThan(x, 0) ) {
return jsnums.makeFloat(1); return plt.baselib.numbers.makeFloat(1);
} else if ( jsnums.lessThan(x, 0) ) { } else if ( plt.baselib.numbers.lessThan(x, 0) ) {
return jsnums.makeFloat(-1); return plt.baselib.numbers.makeFloat(-1);
} else { } else {
return jsnums.makeFloat(0); return plt.baselib.numbers.makeFloat(0);
} }
} else { } else {
if ( jsnums.greaterThan(x, 0) ) { if ( plt.baselib.numbers.greaterThan(x, 0) ) {
return 1; return 1;
} else if ( jsnums.lessThan(x, 0) ) { } else if ( plt.baselib.numbers.lessThan(x, 0) ) {
return -1; return -1;
} else { } else {
return 0; return 0;
@ -1952,7 +1965,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
testArgument(MACHINE, testArgument(MACHINE,
'integer', 'integer',
jsnums.isInteger, plt.baselib.numbers.isInteger,
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'sgn'); 'sgn');
@ -1983,7 +1996,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
MACHINE.env[MACHINE.env.length-1], MACHINE.env[MACHINE.env.length-1],
0, 0,
'string->number'); 'string->number');
return jsnums.fromString(MACHINE.env[MACHINE.env.length-1].toString()); return plt.baselib.numbers.fromString(MACHINE.env[MACHINE.env.length-1].toString());
}); });
@ -1993,7 +2006,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
installPrimitiveProcedure( installPrimitiveProcedure(
'format', 'format',
plt.baselib.arity.arityAtLeast(1), plt.baselib.arity.makeArityAtLeast(1),
function(MACHINE) { function(MACHINE) {
var args = [], i, formatString; var args = [], i, formatString;
testArgument(MACHINE, testArgument(MACHINE,
@ -2058,7 +2071,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
var constructorValue = var constructorValue =
makePrimitiveProcedure( makePrimitiveProcedure(
constructorName, constructorName,
jsnums.toFixnum(initFieldCount), plt.baselib.numbers.toFixnum(initFieldCount),
function(MACHINE) { function(MACHINE) {
var args = []; var args = [];
for(var i = 0; i < initFieldCount; i++) { for(var i = 0; i < initFieldCount; i++) {
@ -2083,7 +2096,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
// FIXME: typechecks // FIXME: typechecks
return structType.accessor( return structType.accessor(
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 2])); plt.baselib.numbers.toFixnum(MACHINE.env[MACHINE.env.length - 2]));
}); });
accessorValue.structType = structType; accessorValue.structType = structType;
@ -2095,7 +2108,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
// FIXME: typechecks // FIXME: typechecks
return structType.mutator( return structType.mutator(
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
jsnums.toFixnum(MACHINE.env[MACHINE.env.length - 2]), plt.baselib.numbers.toFixnum(MACHINE.env[MACHINE.env.length - 2]),
MACHINE.env[MACHINE.env.length - 3]); MACHINE.env[MACHINE.env.length - 3]);
}); });
mutatorValue.structType = structType; mutatorValue.structType = structType;
@ -2144,7 +2157,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
return structType.accessor( return structType.accessor(
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
jsnums.toFixnum(index)); plt.baselib.numbers.toFixnum(index));
}); });
}); });
@ -2170,7 +2183,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
function(MACHINE) { function(MACHINE) {
return structType.mutator( return structType.mutator(
MACHINE.env[MACHINE.env.length - 1], MACHINE.env[MACHINE.env.length - 1],
jsnums.toFixnum(index), plt.baselib.numbers.toFixnum(index),
MACHINE.env[MACHINE.env.length - 2]); MACHINE.env[MACHINE.env.length - 2]);
}); });
}); });
@ -2534,6 +2547,15 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['NULL'] = NULL; exports['NULL'] = NULL;
exports['VOID'] = VOID; exports['VOID'] = VOID;
exports['NEGATIVE_ZERO'] = NEGATIVE_ZERO;
exports['INF'] = INF;
exports['NEGATIVE_INF'] = NEGATIVE_INF;
exports['NAN'] = NAN;
exports['testArgument'] = testArgument; exports['testArgument'] = testArgument;
exports['testArity'] = testArity; exports['testArity'] = testArity;
@ -2571,6 +2593,11 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['makePair'] = makePair; exports['makePair'] = makePair;
exports['makeVector'] = makeVector; exports['makeVector'] = makeVector;
exports['makeBox'] = makeBox; exports['makeBox'] = makeBox;
exports['makeFloat'] = makeFloat;
exports['makeRational'] = makeRational;
exports['makeBignum'] = makeBignum;
exports['makeComplex'] = makeComplex;
// Type predicates // Type predicates
@ -2581,6 +2608,9 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['isOutputStringPort'] = isOutputStringPort; exports['isOutputStringPort'] = isOutputStringPort;
exports['isBox'] = isBox; exports['isBox'] = isBox;
exports['isString'] = isString; exports['isString'] = isString;
exports['isNumber'] = isNumber;
exports['isNatural'] = isNatural;
exports['isReal'] = isReal;
exports['equals'] = equals; exports['equals'] = equals;
exports['toDomNode'] = toDomNode; exports['toDomNode'] = toDomNode;
@ -2588,7 +2618,7 @@ if(this['plt'] === undefined) { this['plt'] = {}; }
exports['toDisplayedString'] = toDisplayedString; exports['toDisplayedString'] = toDisplayedString;
exports['ArityAtLeast'] = plt.baselib.arity.ArityAtLeast; exports['ArityAtLeast'] = plt.baselib.arity.ArityAtLeast;
exports['arityAtLeast'] = plt.baselib.arity.arityAtLeast; exports['makeArityAtLeast'] = plt.baselib.arity.makeArityAtLeast;
exports['isArityMatching'] = plt.baselib.arity.isArityMatching; exports['isArityMatching'] = plt.baselib.arity.isArityMatching;
exports['heir'] = heir; exports['heir'] = heir;

View File

@ -619,27 +619,27 @@ All values should support the following functions
Numbers are represented with the Numbers are represented with the
@link["https://github.com/dyoo/js-numbers"]{js-numbers} JavaScript @link["https://github.com/dyoo/js-numbers"]{js-numbers} JavaScript
library, which introduces a @tt{jsnums} namespace which provides the library. We re-exports it as a @tt{plt.baselib.numbers} namespace
numeric tower API. which provides the numeric tower API.
Example uses of the @tt{js-numbers} library include: Example uses of the @tt{plt.baselib.numbers} library include:
@itemlist[ @itemlist[
@item{Creating integers: @verbatim{42} @verbatim{16}} @item{Creating integers: @verbatim{42} @verbatim{16}}
@item{Creating big integers: @verbatim{jsnums.makeBignum("29837419826")}} @item{Creating big integers: @verbatim{plt.baselib.numbers.makeBignum("29837419826")}}
@item{Creating floats: @verbatim{jsnums.makeFloat(3.1415)}} @item{Creating floats: @verbatim{plt.baselib.numbers.makeFloat(3.1415)}}
@item{Predicate for numbers: @verbatim{jsnums.isSchemeNumber(42)}} @item{Predicate for numbers: @verbatim{plt.baselib.numbers.isSchemeNumber(42)}}
@item{Adding two numbers together: @verbatim{jsnums.add(42, jsnums.makeFloat(3.1415))}} @item{Adding two numbers together: @verbatim{plt.baselib.numbers.add(42, plt.baselib.numbers.makeFloat(3.1415))}}
@item{Converting a jsnums number back into native JavaScript floats: @verbatim{jsnums.toFixnum(...)}} @item{Converting a plt.baselib.numbers number back into native JavaScript floats: @verbatim{plt.baselib.numbers.toFixnum(...)}}
] ]
Do all arithmetic using the functions in the @tt{jsnums} namespace. Do all arithmetic using the functions in the @tt{plt.baselib.numbers} namespace.
One thing to also remember to do is apply @tt{jsnums.toFixnum} to any One thing to also remember to do is apply @tt{plt.baselib.numbers.toFixnum} to any
native JavaScript function that expects numbers. native JavaScript function that expects numbers.