From 6301e0b6374cecc5599665be14d6ddc6a31ce1e8 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Wed, 23 Apr 2014 21:59:50 -0500 Subject: All: TCO let* and quasiquote. --- js/core.js | 2 +- js/step5_tco.js | 4 +++- js/step6_file.js | 4 +++- js/step7_quote.js | 7 +++++-- js/step8_macros.js | 7 +++++-- js/step9_interop.js | 7 +++++-- js/stepA_more.js | 7 +++++-- js/types.js | 3 ++- 8 files changed, 29 insertions(+), 12 deletions(-) (limited to 'js') diff --git a/js/core.js b/js/core.js index f9e478e..b5a52e0 100644 --- a/js/core.js +++ b/js/core.js @@ -193,9 +193,9 @@ var ns = {'type': types._obj_type, 'rest': rest, 'empty?': empty_Q, 'count': count, - 'conj': conj, 'apply': apply, 'map': map, + 'conj': conj, 'with-meta': with_meta, 'meta': meta, diff --git a/js/step5_tco.js b/js/step5_tco.js index 9335aa8..7640327 100644 --- a/js/step5_tco.js +++ b/js/step5_tco.js @@ -52,7 +52,9 @@ function _EVAL(ast, env) { for (var i=0; i < a1.length; i+=2) { let_env.set(a1[i].value, EVAL(a1[i+1], let_env)); } - return EVAL(a2, let_env); + ast = a2; + env = let_env; + break; case "do": eval_ast(ast.slice(1, -1), env); ast = ast[ast.length-1]; diff --git a/js/step6_file.js b/js/step6_file.js index 85de49e..0dfe71e 100644 --- a/js/step6_file.js +++ b/js/step6_file.js @@ -52,7 +52,9 @@ function _EVAL(ast, env) { for (var i=0; i < a1.length; i+=2) { let_env.set(a1[i].value, EVAL(a1[i+1], let_env)); } - return EVAL(a2, let_env); + ast = a2; + env = let_env; + break; case "do": eval_ast(ast.slice(1, -1), env); ast = ast[ast.length-1]; diff --git a/js/step7_quote.js b/js/step7_quote.js index 8676d07..067d68e 100644 --- a/js/step7_quote.js +++ b/js/step7_quote.js @@ -72,11 +72,14 @@ function _EVAL(ast, env) { for (var i=0; i < a1.length; i+=2) { let_env.set(a1[i].value, EVAL(a1[i+1], let_env)); } - return EVAL(a2, let_env); + ast = a2; + env = let_env; + break; case "quote": return a1; case "quasiquote": - return EVAL(quasiquote(a1), env); + ast = quasiquote(a1); + break; case "do": eval_ast(ast.slice(1, -1), env); ast = ast[ast.length-1]; diff --git a/js/step8_macros.js b/js/step8_macros.js index dca7beb..2ddb56c 100644 --- a/js/step8_macros.js +++ b/js/step8_macros.js @@ -90,11 +90,14 @@ function _EVAL(ast, env) { for (var i=0; i < a1.length; i+=2) { let_env.set(a1[i].value, EVAL(a1[i+1], let_env)); } - return EVAL(a2, let_env); + ast = a2; + env = let_env; + break; case "quote": return a1; case "quasiquote": - return EVAL(quasiquote(a1), env); + ast = quasiquote(a1); + break; case 'defmacro!': var func = EVAL(a2, env); func._ismacro_ = true; diff --git a/js/step9_interop.js b/js/step9_interop.js index e95b4ca..3988da1 100644 --- a/js/step9_interop.js +++ b/js/step9_interop.js @@ -90,11 +90,14 @@ function _EVAL(ast, env) { for (var i=0; i < a1.length; i+=2) { let_env.set(a1[i].value, EVAL(a1[i+1], let_env)); } - return EVAL(a2, let_env); + ast = a2; + env = let_env; + break; case "quote": return a1; case "quasiquote": - return EVAL(quasiquote(a1), env); + ast = quasiquote(a1); + break; case 'defmacro!': var func = EVAL(a2, env); func._ismacro_ = true; diff --git a/js/stepA_more.js b/js/stepA_more.js index 58840eb..6058da1 100644 --- a/js/stepA_more.js +++ b/js/stepA_more.js @@ -90,11 +90,14 @@ function _EVAL(ast, env) { for (var i=0; i < a1.length; i+=2) { let_env.set(a1[i].value, EVAL(a1[i+1], let_env)); } - return EVAL(a2, let_env); + ast = a2; + env = let_env; + break; case "quote": return a1; case "quasiquote": - return EVAL(quasiquote(a1), env); + ast = quasiquote(a1); + break; case 'defmacro!': var func = EVAL(a2, env); func._ismacro_ = true; diff --git a/js/types.js b/js/types.js index 889e154..d288231 100644 --- a/js/types.js +++ b/js/types.js @@ -107,6 +107,7 @@ function _function(Eval, Env, ast, env, params) { fn.__meta__ = null; fn.__ast__ = ast; fn.__gen_env__ = function(args) { return new Env(env, params, args); }; + fn._ismacro_ = false; return fn; } function _function_Q(obj) { return typeof obj == "function"; } @@ -131,7 +132,7 @@ function _vector() { v.__isvector__ = true; return v; } -function _vector_Q(obj) { return Array.isArray(obj) && obj.__isvector__; } +function _vector_Q(obj) { return Array.isArray(obj) && !!obj.__isvector__; } -- cgit v1.2.3