aboutsummaryrefslogtreecommitdiff
path: root/js/step9_interop.js
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
committerJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
commit8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (patch)
tree13e5b2878f19ee24272ead8a92a9cb84b33ad0e5 /js/step9_interop.js
parenta05f7822b10ed4cdd61ed8384299a003baf1c1c6 (diff)
downloadmal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.tar.gz
mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.zip
All: move some fns to core. Major cleanup.
- Don't import/require core until step4. - Define cond/or macros from step8
Diffstat (limited to 'js/step9_interop.js')
-rw-r--r--js/step9_interop.js14
1 files changed, 5 insertions, 9 deletions
diff --git a/js/step9_interop.js b/js/step9_interop.js
index 4987931..1fd07d4 100644
--- a/js/step9_interop.js
+++ b/js/step9_interop.js
@@ -147,20 +147,16 @@ function PRINT(exp) {
// repl
var repl_env = new Env();
var rep = function(str) { return PRINT(EVAL(READ(str), repl_env)); };
-_ref = function (k,v) { repl_env.set(k, v); }
-// Import core functions
+// core.js: defined using javascript
for (var n in core.ns) { repl_env.set(n, core.ns[n]); }
+repl_env.set('eval', function(ast) { return EVAL(ast, repl_env); });
-_ref('read-string', reader.read_str);
-_ref('eval', function(ast) { return EVAL(ast, repl_env); });
-_ref('slurp', function(f) {
- return require('fs').readFileSync(f, 'utf-8');
-});
-
-// Defined using the language itself
+// core.mal: defined using the language itself
rep("(def! not (fn* (a) (if a false true)))");
rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))");
+rep("(defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw \"odd number of forms to cond\")) (cons 'cond (rest (rest xs)))))))");
+rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))");
if (typeof process !== 'undefined' && process.argv.length > 2) {
for (var i=2; i < process.argv.length; i++) {