0
@@ -19,7 +19,7 @@ function parse(expr) {
0
function eval_(exp, env) {
0
//print("eval: " + JSON.stringify(exp) + " :sntx: " + exp.sntx);
0
if (selfEval(exp)) return eval(exp); // JS eval for native type
0
- else if (quoted(exp)) return eval
(exp); // JS eval to unescape0
+ else if (quoted(exp)) return eval
Quoted(exp);0
else if (variableRef(exp)) return variableValue(exp, env);
0
else if (list(exp)) return evalList(exp, env);
0
else if (sequence(exp)) return evalSeq(exp, env);
0
@@ -41,7 +41,14 @@ function evalList(operands, env) {
0
function selfEval(exp) { return (!isNaN(exp)); }
0
-function quoted(exp) { return ((typeof exp) == 'string') && exp[0] == '"'; }
0
+function quoted(exp) { return (typeof exp == 'string' || exp instanceof String) && (exp[0] == '"' || exp.alien); }
0
+function evalQuoted(exp) {
0
+ if (exp.alien) return exp;
0
+ // JS eval to unescape
0
+ var str = new String(eval(exp));
0
function variableRef(exp) { return (typeof exp) == 'string'; }
0
function variableValue(exp, env, isMacro) {
0
@@ -157,9 +164,7 @@ function primitiveParams(operation) { return operation[1]; }
0
function applyPrimitive(operation, operands, env) {
0
var primFn = primitiveBody(operation);
0
- //print("calling prim " + primFn + " with " + JSON.stringify(operands));
0
if (typeof primFn == "function") return primFn.call(null, operands, env);
0
- //else if (primFn = primitives[primFn]) return primFn.call(null, operands, env);
0
else throw "Unrecognized primitive: " + operation[1] + ", most certainly a bug.";
0
@@ -169,7 +174,7 @@ function typeDispatch(op) {
0
return function(operands, env) {
0
var first = operands.first(), typeFn;
0
if (typeof first == 'number') typeFn = wNum[op];
0
- else if (typeof first == 'string'
) typeFn = wString[op];
0
+ else if (typeof first == 'string'
|| first instanceof String) typeFn = wString[op];
0
else if (first instanceof Array) typeFn = wArray[op];
0
else throw "Can't dispatch operation " + op + " to " + first + ", unknown type.";
0
@@ -280,7 +285,6 @@ addPrimitive('lcurry', ['lambda', 'parameters*'], opEval(
0
addPrimitive('rcurry', ['lambda', 'parameters*'], opEval(
0
function(operands, env) {
0
var fn = operands.first();
0
- print("inprim " + operands);
0
if (lambda(fn)) return makeCurriedLambda(fn, rightCurry(fn, operands.tail()));
0
else if (primitive(fn)) return makeCurriedPrimitive(fn, rightCurry(fn, operands.tail()));
0
else throw "The first parameter of rightCurry should be a function."
0
@@ -290,8 +294,8 @@ addPrimitive('ncurry', ['lambda', 'index', 'parameter'], opEval(
0
var fn = operands.first();
0
if (typeof idx != "number") throw "Second parameter of ncurry must be a number."
0
- if (lambda(fn)) return makeCurriedLambda(fn, nCurry(fn, idx, operands.tail()));
0
- else if (primitive(fn)) return makeCurriedPrimitive(fn, nCurry(fn, idx, operands.tail()));
0
+ if (lambda(fn)) return makeCurriedLambda(fn, nCurry(fn, idx, operands[2]));
0
+ else if (primitive(fn)) return makeCurriedPrimitive(fn, nCurry(fn, idx, operands[2]));
0
else throw "The first parameter of nurry should be a function."
0
addPrimitive('=', ['symbol', 'value'], function(operands, env) {
0
@@ -308,7 +312,7 @@ addPrimitive('=', ['symbol', 'value'], function(operands, env) {
0
addPrimitive('==', ['loperand', 'roperand'], opEval(
0
function(operands, env) {
0
if (operands[0] instanceof Array) operands[0].toString() == operands[1].toString();
0
- else return operands[0]
== operands[1];
0
+ else return operands[0]
.valueOf() == operands[1].valueOf();
0
})); // TODO accept n parameters
0
addPrimitive('join', ['separator'], opEval(typeDispatch('join')));
0
addPrimitive('<', ['loperand', 'roperand'], opEval(function(operands, env) { return operands[0] < operands[1]; }));
Comments
No one has commented yet.