diff --git a/ada.2/step8_macros.adb b/ada.2/step8_macros.adb index 3786b8ed8a..4e9db3ec6e 100644 --- a/ada.2/step8_macros.adb +++ b/ada.2/step8_macros.adb @@ -401,12 +401,7 @@ procedure Step8_Macros is & " (list 'if (first xs)" & " (if (> (count xs) 1) (nth xs 1)" & " (throw ""odd number of forms to cond""))" - & " (cons 'cond (rest (rest xs)))))))" - & "(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))))))))"; + & " (cons 'cond (rest (rest xs)))))))"; Repl : constant Envs.Ptr := Envs.New_Env; function Eval_Builtin (Args : in Types.T_Array) return Types.T is begin diff --git a/ada.2/step9_try.adb b/ada.2/step9_try.adb index bc26dd0f98..162eec10f7 100644 --- a/ada.2/step9_try.adb +++ b/ada.2/step9_try.adb @@ -431,12 +431,7 @@ procedure Step9_Try is & " (list 'if (first xs)" & " (if (> (count xs) 1) (nth xs 1)" & " (throw ""odd number of forms to cond""))" - & " (cons 'cond (rest (rest xs)))))))" - & "(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))))))))"; + & " (cons 'cond (rest (rest xs)))))))"; Repl : constant Envs.Ptr := Envs.New_Env; function Eval_Builtin (Args : in Types.T_Array) return Types.T is begin diff --git a/ada.2/stepa_mal.adb b/ada.2/stepa_mal.adb index 0c66590403..ba52c2c05e 100644 --- a/ada.2/stepa_mal.adb +++ b/ada.2/stepa_mal.adb @@ -438,15 +438,6 @@ procedure StepA_Mal is & " (if (> (count xs) 1) (nth xs 1)" & " (throw ""odd number of forms to cond""))" & " (cons 'cond (rest (rest xs)))))))" - & "(def! inc (fn* [x] (+ x 1)))" - & "(def! gensym (let* [counter (atom 0)]" - & " (fn* [] (symbol (str ""G__"" (swap! counter inc))))))" - & "(defmacro! or (fn* (& xs)" - & " (if (empty? xs) nil" - & " (if (= 1 (count xs)) (first xs)" - & " (let* (condvar (gensym))" - & " `(let* (~condvar ~(first xs))" - & " (if ~condvar ~condvar (or ~@(rest xs)))))))))" & "(def! *host-language* ""ada.2"")"; Repl : constant Envs.Ptr := Envs.New_Env; function Eval_Builtin (Args : in Types.T_Array) return Types.T is diff --git a/ada/step8_macros.adb b/ada/step8_macros.adb index 25cc8f42b7..40e4624c9d 100644 --- a/ada/step8_macros.adb +++ b/ada/step8_macros.adb @@ -527,7 +527,6 @@ begin RE ("(def! not (fn* (a) (if a false true)))"); RE ("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))"); RE ("(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)))))))"); - RE ("(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))))))))"); -- Command line processing. diff --git a/ada/step9_try.adb b/ada/step9_try.adb index bd7fcd5c12..fcbba5c583 100644 --- a/ada/step9_try.adb +++ b/ada/step9_try.adb @@ -580,7 +580,6 @@ begin RE ("(def! not (fn* (a) (if a false true)))"); RE ("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))"); RE ("(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)))))))"); - RE ("(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))))))))"); -- Command line processing. diff --git a/ada/stepa_mal.adb b/ada/stepa_mal.adb index 1f1c049a10..b0c9c040af 100644 --- a/ada/stepa_mal.adb +++ b/ada/stepa_mal.adb @@ -580,9 +580,6 @@ begin RE ("(def! not (fn* (a) (if a false true)))"); RE ("(def! load-file (fn* (f) (eval (read-string (str ""(do "" (slurp f) "")"")))))"); RE ("(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)))))))"); - RE ("(def! inc (fn* [x] (+ x 1)))"); - RE ("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str ""G__"" (swap! counter inc))))))"); - RE ("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); -- Command line processing. diff --git a/awk/step8_macros.awk b/awk/step8_macros.awk index 50a7fde329..85fe014ca4 100644 --- a/awk/step8_macros.awk +++ b/awk/step8_macros.awk @@ -507,7 +507,6 @@ function main(str, ret, i, idx) 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))))))))") idx = types_allocate() env_set(repl_env, "'*ARGV*", "(" idx) diff --git a/awk/step9_try.awk b/awk/step9_try.awk index 79e9ed1af2..18583c670a 100644 --- a/awk/step9_try.awk +++ b/awk/step9_try.awk @@ -569,7 +569,6 @@ function main(str, ret, i, idx) 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))))))))") idx = types_allocate() env_set(repl_env, "'*ARGV*", "(" idx) diff --git a/awk/stepA_mal.awk b/awk/stepA_mal.awk index 8e7fae0d3b..ce5773b555 100644 --- a/awk/stepA_mal.awk +++ b/awk/stepA_mal.awk @@ -572,9 +572,6 @@ function main(str, ret, i, idx) 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("(def! inc (fn* [x] (+ x 1)))") - rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") - rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") idx = types_allocate() env_set(repl_env, "'*ARGV*", "(" idx) diff --git a/bash/step8_macros.sh b/bash/step8_macros.sh index d86cdd64cf..72b010dac6 100755 --- a/bash/step8_macros.sh +++ b/bash/step8_macros.sh @@ -250,7 +250,6 @@ ENV_SET "${REPL_ENV}" "${r}" "${argv}"; 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))))))))" # load/run file from command line (then exit) if [[ "${1}" ]]; then diff --git a/bash/step9_try.sh b/bash/step9_try.sh index 7567050a01..29fa329b2b 100755 --- a/bash/step9_try.sh +++ b/bash/step9_try.sh @@ -263,7 +263,6 @@ ENV_SET "${REPL_ENV}" "${r}" "${argv}"; 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))))))))" # load/run file from command line (then exit) if [[ "${1}" ]]; then diff --git a/bash/stepA_mal.sh b/bash/stepA_mal.sh index d3df641b32..e414b7abe3 100755 --- a/bash/stepA_mal.sh +++ b/bash/stepA_mal.sh @@ -272,9 +272,6 @@ REP "(def! *host-language* \"bash\")" 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 "(def! inc (fn* [x] (+ x 1)))" -REP "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" -REP "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) \`(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" # load/run file from command line (then exit) if [[ "${1}" ]]; then diff --git a/basic/step8_macros.in.bas b/basic/step8_macros.in.bas index c2c6f8edff..09397a18cc 100755 --- a/basic/step8_macros.in.bas +++ b/basic/step8_macros.in.bas @@ -537,10 +537,6 @@ MAIN: A$=A$+" forms to cond"+CHR$(34)+")) (cons 'cond (rest (rest xs)))))))" GOSUB RE:AY=R:GOSUB RELEASE - A$="(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs)" - A$=A$+" `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))" - GOSUB RE:AY=R:GOSUB RELEASE - REM load the args file A$="(def! -*ARGS*- (load-file "+CHR$(34)+".args.mal"+CHR$(34)+"))" GOSUB RE:AY=R:GOSUB RELEASE diff --git a/basic/step9_try.in.bas b/basic/step9_try.in.bas index 26a18d771c..d5e76c3c41 100755 --- a/basic/step9_try.in.bas +++ b/basic/step9_try.in.bas @@ -570,10 +570,6 @@ MAIN: A$=A$+" forms to cond"+CHR$(34)+")) (cons 'cond (rest (rest xs)))))))" GOSUB RE:AY=R:GOSUB RELEASE - A$="(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs)" - A$=A$+" `(let* (or_FIXME ~(first xs)) (if or_FIXME or_FIXME (or ~@(rest xs))))))))" - GOSUB RE:AY=R:GOSUB RELEASE - REM load the args file A$="(def! -*ARGS*- (load-file "+CHR$(34)+".args.mal"+CHR$(34)+"))" GOSUB RE:AY=R:GOSUB RELEASE diff --git a/basic/stepA_mal.in.bas b/basic/stepA_mal.in.bas index 9e6297dcf5..bfbef8578d 100755 --- a/basic/stepA_mal.in.bas +++ b/basic/stepA_mal.in.bas @@ -569,18 +569,6 @@ MAIN: A$=A$+" forms to cond"+CHR$(34)+")) (cons 'cond (rest (rest xs)))))))" GOSUB RE:AY=R:GOSUB RELEASE - A$="(def! inc (fn* [x] (+ x 1)))" - GOSUB RE:AY=R:GOSUB RELEASE - - A$="(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "+CHR$(34) - A$=A$+"G__"+CHR$(34)+" (swap! counter inc))))))" - GOSUB RE:AY=R:GOSUB RELEASE - - A$="(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs)" - A$=A$+" (let* (c (gensym)) `(let* (~c ~(first xs))" - A$=A$+" (if ~c ~c (or ~@(rest xs)))))))))" - GOSUB RE:AY=R:GOSUB RELEASE - REM load the args file A$="(def! -*ARGS*- (load-file "+CHR$(34)+".args.mal"+CHR$(34)+"))" GOSUB RE:AY=R:GOSUB RELEASE diff --git a/bbc-basic/step8_macros.bbc b/bbc-basic/step8_macros.bbc index a71954d098..5e9be483c5 100644 --- a/bbc-basic/step8_macros.bbc +++ b/bbc-basic/step8_macros.bbc @@ -22,7 +22,6 @@ RESTORE +0 DATA (def! not (fn* (a) (if a false true))) DATA (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) DATA (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))))))) -DATA (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)))))))) DATA "" REPEAT READ form$ diff --git a/bbc-basic/step9_try.bbc b/bbc-basic/step9_try.bbc index 278556b327..f6524e3af7 100644 --- a/bbc-basic/step9_try.bbc +++ b/bbc-basic/step9_try.bbc @@ -22,7 +22,6 @@ RESTORE +0 DATA (def! not (fn* (a) (if a false true))) DATA (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) DATA (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))))))) -DATA (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)))))))) DATA "" REPEAT READ form$ diff --git a/bbc-basic/stepA_mal.bbc b/bbc-basic/stepA_mal.bbc index 062a7fc4e0..44c990cb74 100644 --- a/bbc-basic/stepA_mal.bbc +++ b/bbc-basic/stepA_mal.bbc @@ -22,9 +22,6 @@ RESTORE +0 DATA (def! not (fn* (a) (if a false true))) DATA (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) DATA (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))))))) -DATA (def! inc (fn* [x] (+ x 1))) -DATA (def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc)))))) -DATA (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs))))))))) DATA (def! *host-language* "BBC BASIC V") DATA "" REPEAT diff --git a/c/step8_macros.c b/c/step8_macros.c index 335642ba85..5dede9712c 100644 --- a/c/step8_macros.c +++ b/c/step8_macros.c @@ -291,7 +291,6 @@ void init_repl_env(int argc, char *argv[]) { RE(repl_env, "", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE(repl_env, "", "(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)))))))"); - RE(repl_env, "", "(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))))))))"); } int main(int argc, char *argv[]) diff --git a/c/step9_try.c b/c/step9_try.c index 9c555aca1f..c4d262fe1b 100644 --- a/c/step9_try.c +++ b/c/step9_try.c @@ -316,7 +316,6 @@ void init_repl_env(int argc, char *argv[]) { RE(repl_env, "", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE(repl_env, "", "(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)))))))"); - RE(repl_env, "", "(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))))))))"); } int main(int argc, char *argv[]) diff --git a/c/stepA_mal.c b/c/stepA_mal.c index 4960cb519e..2c8f6b0d77 100644 --- a/c/stepA_mal.c +++ b/c/stepA_mal.c @@ -322,9 +322,6 @@ void init_repl_env(int argc, char *argv[]) { RE(repl_env, "", "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE(repl_env, "", "(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)))))))"); - RE(repl_env, "", "(def! inc (fn* [x] (+ x 1)))"); - RE(repl_env, "", "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); - RE(repl_env, "", "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); } int main(int argc, char *argv[]) diff --git a/chuck/step8_macros.ck b/chuck/step8_macros.ck index f52e0de4a7..5c185d918d 100644 --- a/chuck/step8_macros.ck +++ b/chuck/step8_macros.ck @@ -435,9 +435,7 @@ fun string rep(string input) 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))))))))"); fun void main() { diff --git a/chuck/step9_try.ck b/chuck/step9_try.ck index 539d1d8fd1..ecc45d8b0f 100644 --- a/chuck/step9_try.ck +++ b/chuck/step9_try.ck @@ -452,9 +452,7 @@ fun string rep(string input) 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))))))))"); fun void main() { diff --git a/chuck/stepA_mal.ck b/chuck/stepA_mal.ck index 51d1cf47ff..afe6b8d766 100644 --- a/chuck/stepA_mal.ck +++ b/chuck/stepA_mal.ck @@ -454,13 +454,8 @@ fun string rep(string input) 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("(def! inc (fn* [x] (+ x 1)))"); -rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); -rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); - fun void main() { int done; diff --git a/clojure/src/mal/step8_macros.cljc b/clojure/src/mal/step8_macros.cljc index 9cf709917e..d0d567417b 100644 --- a/clojure/src/mal/step8_macros.cljc +++ b/clojure/src/mal/step8_macros.cljc @@ -153,7 +153,6 @@ (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))))))))") ;; repl loop (defn repl-loop [] diff --git a/clojure/src/mal/step9_try.cljc b/clojure/src/mal/step9_try.cljc index e6ff06716d..fd172375cd 100644 --- a/clojure/src/mal/step9_try.cljc +++ b/clojure/src/mal/step9_try.cljc @@ -170,7 +170,6 @@ (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))))))))") ;; repl loop (defn repl-loop [] diff --git a/clojure/src/mal/stepA_mal.cljc b/clojure/src/mal/stepA_mal.cljc index 6cb5f3e949..5a26159a8d 100644 --- a/clojure/src/mal/stepA_mal.cljc +++ b/clojure/src/mal/stepA_mal.cljc @@ -180,9 +180,6 @@ (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 "(def! inc (fn* [x] (+ x 1)))") -(rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") ;; repl loop (defn repl-loop [] diff --git a/coffee/step8_macros.coffee b/coffee/step8_macros.coffee index 3b552f8d54..98319a1036 100644 --- a/coffee/step8_macros.coffee +++ b/coffee/step8_macros.coffee @@ -107,7 +107,6 @@ repl_env.set types._symbol('*ARGV*'), [] 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 process? && process.argv.length > 2 repl_env.set types._symbol('*ARGV*'), process.argv[3..] diff --git a/coffee/step9_try.coffee b/coffee/step9_try.coffee index d5bbe010a3..71d479edee 100644 --- a/coffee/step9_try.coffee +++ b/coffee/step9_try.coffee @@ -116,7 +116,6 @@ repl_env.set types._symbol('*ARGV*'), [] 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 process? && process.argv.length > 2 repl_env.set types._symbol('*ARGV*'), process.argv[3..] diff --git a/coffee/stepA_mal.coffee b/coffee/stepA_mal.coffee index 5a18714e75..7f0030b32e 100644 --- a/coffee/stepA_mal.coffee +++ b/coffee/stepA_mal.coffee @@ -123,9 +123,6 @@ rep("(def! *host-language* \"CoffeeScript\")") 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("(def! inc (fn* [x] (+ x 1)))"); -rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); -rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if process? && process.argv.length > 2 repl_env.set types._symbol('*ARGV*'), process.argv[3..] diff --git a/common-lisp/src/step8_macros.lisp b/common-lisp/src/step8_macros.lisp index e27ac6cca8..ab75d9c6c8 100644 --- a/common-lisp/src/step8_macros.lisp +++ b/common-lisp/src/step8_macros.lisp @@ -228,7 +228,6 @@ (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))))))))") (defvar *use-readline-p* nil) diff --git a/common-lisp/src/step9_try.lisp b/common-lisp/src/step9_try.lisp index 87cc341f9b..d8bd04d8ec 100644 --- a/common-lisp/src/step9_try.lisp +++ b/common-lisp/src/step9_try.lisp @@ -251,7 +251,6 @@ (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))))))))") (defvar *use-readline-p* nil) diff --git a/common-lisp/src/stepA_mal.lisp b/common-lisp/src/stepA_mal.lisp index c9d7c33468..adb17bfb6f 100644 --- a/common-lisp/src/stepA_mal.lisp +++ b/common-lisp/src/stepA_mal.lisp @@ -259,9 +259,6 @@ (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 "(def! *host-language* \"common-lisp\")") -(rep "(def! inc (fn* [x] (+ x 1)))") -(rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") (defvar *use-readline-p* nil) diff --git a/cpp/step8_macros.cpp b/cpp/step8_macros.cpp index 32d450ded5..183039d29e 100644 --- a/cpp/step8_macros.cpp +++ b/cpp/step8_macros.cpp @@ -280,7 +280,6 @@ static malValuePtr macroExpand(malValuePtr obj, malEnvPtr env) static const char* malFunctionTable[] = { "(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)))))))", - "(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))))))))", "(def! not (fn* (cond) (if cond false true)))", "(def! load-file (fn* (filename) \ (eval (read-string (str \"(do \" (slurp filename) \")\")))))", diff --git a/cpp/step9_try.cpp b/cpp/step9_try.cpp index 7f776bd6a0..ea9f8ce50c 100644 --- a/cpp/step9_try.cpp +++ b/cpp/step9_try.cpp @@ -329,7 +329,6 @@ static malValuePtr macroExpand(malValuePtr obj, malEnvPtr env) static const char* malFunctionTable[] = { "(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)))))))", - "(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))))))))", "(def! not (fn* (cond) (if cond false true)))", "(def! load-file (fn* (filename) \ (eval (read-string (str \"(do \" (slurp filename) \")\")))))", diff --git a/cpp/stepA_mal.cpp b/cpp/stepA_mal.cpp index 93a6f1d95e..15ab8192af 100644 --- a/cpp/stepA_mal.cpp +++ b/cpp/stepA_mal.cpp @@ -330,12 +330,9 @@ static malValuePtr macroExpand(malValuePtr obj, malEnvPtr env) static const char* malFunctionTable[] = { "(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)))))))", - "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", "(def! not (fn* (cond) (if cond false true)))", "(def! load-file (fn* (filename) \ (eval (read-string (str \"(do \" (slurp filename) \")\")))))", - "(def! inc (fn* [x] (+ x 1)))", - "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", "(def! *host-language* \"C++\")", }; diff --git a/crystal/step8_macros.cr b/crystal/step8_macros.cr index cca371028b..d118c15f05 100755 --- a/crystal/step8_macros.cr +++ b/crystal/step8_macros.cr @@ -231,7 +231,6 @@ REPL_ENV.set("eval", Mal::Type.new ->(args : Array(Mal::Type)) { Mal.eval(args[0 Mal.rep "(def! not (fn* (a) (if a false true)))" Mal.rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" Mal.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)))))))" -Mal.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))))))))" argv = Mal::List.new REPL_ENV.set("*ARGV*", Mal::Type.new argv) diff --git a/crystal/step9_try.cr b/crystal/step9_try.cr index 5d63bc855c..455c31e189 100755 --- a/crystal/step9_try.cr +++ b/crystal/step9_try.cr @@ -248,7 +248,6 @@ REPL_ENV.set("eval", Mal::Type.new ->(args : Array(Mal::Type)) { Mal.eval(args[0 Mal.rep "(def! not (fn* (a) (if a false true)))" Mal.rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" Mal.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)))))))" -Mal.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))))))))" argv = Mal::List.new REPL_ENV.set("*ARGV*", Mal::Type.new argv) diff --git a/crystal/stepA_mal.cr b/crystal/stepA_mal.cr index 701ffb6ea5..2d7b39b8ca 100755 --- a/crystal/stepA_mal.cr +++ b/crystal/stepA_mal.cr @@ -254,9 +254,6 @@ REPL_ENV.set("eval", Mal::Type.new ->(args : Array(Mal::Type)) { Mal.eval(args[0 Mal.rep "(def! not (fn* (a) (if a false true)))" Mal.rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" Mal.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)))))))" -Mal.rep "(def! inc (fn* [x] (+ x 1)))" -Mal.rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" -Mal.rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" Mal.rep("(def! *host-language* \"crystal\")") argv = Mal::List.new diff --git a/cs/step8_macros.cs b/cs/step8_macros.cs index 3ec240a3cf..6c1d706274 100644 --- a/cs/step8_macros.cs +++ b/cs/step8_macros.cs @@ -227,7 +227,6 @@ static void Main(string[] args) { RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE("(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)))))))"); - RE("(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 (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); diff --git a/cs/step9_try.cs b/cs/step9_try.cs index 0e37436ada..0a8f746fd9 100644 --- a/cs/step9_try.cs +++ b/cs/step9_try.cs @@ -248,7 +248,6 @@ static void Main(string[] args) { RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE("(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)))))))"); - RE("(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 (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); diff --git a/cs/stepA_mal.cs b/cs/stepA_mal.cs index 1f14be8668..70fc0d228c 100644 --- a/cs/stepA_mal.cs +++ b/cs/stepA_mal.cs @@ -249,9 +249,6 @@ static void Main(string[] args) { RE("(def! not (fn* (a) (if a false true)))"); RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE("(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)))))))"); - RE("(def! inc (fn* [x] (+ x 1)))"); - RE("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); - RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); if (args.Length > fileIdx) { RE("(load-file \"" + args[fileIdx] + "\")"); diff --git a/d/step8_macros.d b/d/step8_macros.d index 48b3d2b2e0..a39ff89df7 100644 --- a/d/step8_macros.d +++ b/d/step8_macros.d @@ -263,7 +263,6 @@ void main(string[] args) re("(def! not (fn* (a) (if a false true)))", repl_env); re("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env); re("(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)))))))", repl_env); - re("(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))))))))", repl_env); if (args.length > 1) { diff --git a/d/step9_try.d b/d/step9_try.d index 9070dfa19a..054b38e106 100644 --- a/d/step9_try.d +++ b/d/step9_try.d @@ -292,7 +292,6 @@ void main(string[] args) re("(def! not (fn* (a) (if a false true)))", repl_env); re("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env); re("(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)))))))", repl_env); - re("(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))))))))", repl_env); if (args.length > 1) { diff --git a/d/stepA_mal.d b/d/stepA_mal.d index a669dde7c2..31658e5363 100644 --- a/d/stepA_mal.d +++ b/d/stepA_mal.d @@ -294,9 +294,6 @@ void main(string[] args) re("(def! not (fn* (a) (if a false true)))", repl_env); re("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env); re("(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)))))))", repl_env); - re("(def! inc (fn* [x] (+ x 1)))", repl_env); - re("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env); - re("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env); if (args.length > 1) { diff --git a/dart/step8_macros.dart b/dart/step8_macros.dart index de9fbbf0d7..a8baada8f1 100644 --- a/dart/step8_macros.dart +++ b/dart/step8_macros.dart @@ -27,12 +27,6 @@ void setupEnv(List argv) { " (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))))))))"); } /// Returns `true` if [ast] is a macro call. diff --git a/dart/step9_try.dart b/dart/step9_try.dart index 09bedbeb7e..8d0483759f 100644 --- a/dart/step9_try.dart +++ b/dart/step9_try.dart @@ -27,12 +27,6 @@ void setupEnv(List argv) { " (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))))))))"); } /// Returns `true` if [ast] is a macro call. diff --git a/dart/stepA_mal.dart b/dart/stepA_mal.dart index a1bacce6dd..aee59590d8 100644 --- a/dart/stepA_mal.dart +++ b/dart/stepA_mal.dart @@ -29,20 +29,6 @@ void setupEnv(List argv) { " (nth xs 1) " " (throw \"odd number of forms to cond\")) " " (cons 'cond (rest (rest xs)))))))"); - rep("(def! inc (fn* [x] (+ x 1)))"); - rep("(def! gensym" - " (let* [counter (atom 0)]" - " (fn* []" - " (symbol (str \"G__\" (swap! counter inc))))))"); - rep("(defmacro! or " - " (fn* (& xs) " - " (if (empty? xs) " - " nil " - " (if (= 1 (count xs)) " - " (first xs) " - " (let* (condvar (gensym)) " - " `(let* (~condvar ~(first xs)) " - " (if ~condvar ~condvar (or ~@(rest xs)))))))))"); } /// Returns `true` if [ast] is a macro call. diff --git a/docs/cheatsheet.html b/docs/cheatsheet.html index f3124f3ccc..28719052b3 100644 --- a/docs/cheatsheet.html +++ b/docs/cheatsheet.html @@ -247,9 +247,6 @@

Make-A-Lisp Cheatsheet

step9_try.EXT: EVAL(ast, env): - set *host-language* in repl_env to host language name - - inc: define (using rep()) a function incrementing an integer - - gensym: define using rep()), return unique symbol - - or: use gensym to fix or macro main(args): rep("(println (str \"Mal [\" *host-language* \"]\"))") diff --git a/elisp/step8_macros.el b/elisp/step8_macros.el index d9ed1da364..26c5f445b4 100644 --- a/elisp/step8_macros.el +++ b/elisp/step8_macros.el @@ -181,9 +181,7 @@ (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))))))))") (defun readln (prompt) ;; C-d throws an error diff --git a/elisp/step9_try.el b/elisp/step9_try.el index 7dc47a9676..289478d940 100644 --- a/elisp/step9_try.el +++ b/elisp/step9_try.el @@ -197,9 +197,7 @@ (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))))))))") (defun readln (prompt) ;; C-d throws an error diff --git a/elisp/stepA_mal.el b/elisp/stepA_mal.el index c8a31e5794..c4ae1cc434 100644 --- a/elisp/stepA_mal.el +++ b/elisp/stepA_mal.el @@ -198,12 +198,7 @@ (rep "(def! not (fn* (a) (if a false true)))") (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") - -(rep "(def! inc (fn* [x] (+ x 1)))") -(rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") - (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* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") (defun readln (prompt) ;; C-d throws an error diff --git a/elixir/lib/mix/tasks/step8_macros.ex b/elixir/lib/mix/tasks/step8_macros.ex index abb6e6df3b..45edae1939 100644 --- a/elixir/lib/mix/tasks/step8_macros.ex +++ b/elixir/lib/mix/tasks/step8_macros.ex @@ -42,17 +42,6 @@ defmodule Mix.Tasks.Step8Macros do (cons 'cond (rest (rest xs)))))))" """, env) - # or: - read_eval_print(""" - (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)))))))) - """, env) - Mal.Env.set(env, "eval", %Function{value: fn [ast] -> eval(ast, env) end}) diff --git a/elixir/lib/mix/tasks/step9_try.ex b/elixir/lib/mix/tasks/step9_try.ex index b1b94c8ef2..917b2a2e95 100644 --- a/elixir/lib/mix/tasks/step9_try.ex +++ b/elixir/lib/mix/tasks/step9_try.ex @@ -42,17 +42,6 @@ defmodule Mix.Tasks.Step9Try do (cons 'cond (rest (rest xs)))))))" """, env) - # or: - read_eval_print(""" - (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)))))))) - """, env) - Mal.Env.set(env, "eval", %Function{value: fn [ast] -> eval(ast, env) end}) diff --git a/elixir/lib/mix/tasks/stepA_mal.ex b/elixir/lib/mix/tasks/stepA_mal.ex index b5665ba4e1..340be5a3cf 100644 --- a/elixir/lib/mix/tasks/stepA_mal.ex +++ b/elixir/lib/mix/tasks/stepA_mal.ex @@ -50,28 +50,6 @@ defmodule Mix.Tasks.StepAMal do (cons 'cond (rest (rest xs)))))))" """, env) - # gensym - read_eval_print("(def! inc (fn* [x] (+ x 1)))", env) - read_eval_print(""" - (def! gensym - (let* [counter (atom 0)] - (fn* [] - (symbol (str \"G__\" (swap! counter inc)))))) - """, env) - - # or: - read_eval_print(""" - (defmacro! or - (fn* (& xs) - (if (empty? xs) - nil - (if (= 1 (count xs)) - (first xs) - (let* (condvar (gensym)) - `(let* (~condvar ~(first xs)) - (if ~condvar ~condvar (or ~@(rest xs))))))))) - """, env) - Mal.Env.set(env, "eval", %Function{value: fn [ast] -> eval(ast, env) end}) diff --git a/elm/step8_macros.elm b/elm/step8_macros.elm index 023d1179ae..85d57ce925 100644 --- a/elm/step8_macros.elm +++ b/elm/step8_macros.elm @@ -80,14 +80,6 @@ malInit = (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs)))))))""" - , """(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))))))))""" ] diff --git a/elm/step9_try.elm b/elm/step9_try.elm index 44b3180c1d..ed7d9f71f4 100644 --- a/elm/step9_try.elm +++ b/elm/step9_try.elm @@ -80,14 +80,6 @@ malInit = (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs)))))))""" - , """(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))))))))""" ] diff --git a/elm/stepA_mal.elm b/elm/stepA_mal.elm index fa0e4c03e4..2c7f72f7a3 100644 --- a/elm/stepA_mal.elm +++ b/elm/stepA_mal.elm @@ -81,22 +81,6 @@ malInit = (nth xs 1) (throw "odd number of forms to cond")) (cons 'cond (rest (rest xs)))))))""" - , """(def! inc (fn* [x] (+ x 1)))""" - , """(def! gensym - (let* [counter (atom 0)] - (fn* [] - (symbol (str "G__" (swap! counter inc))))))""" - , """(defmacro! or - (fn* (& xs) - (if (empty? xs) - nil - (if (= 1 (count xs)) - (first xs) - (let* (condvar (gensym)) - `(let* (~condvar ~(first xs)) - (if ~condvar - ~condvar - (or ~@(rest xs)))))))))""" ] diff --git a/erlang/src/step8_macros.erl b/erlang/src/step8_macros.erl index 8f7bccaf20..07d0d5f954 100644 --- a/erlang/src/step8_macros.erl +++ b/erlang/src/step8_macros.erl @@ -20,7 +20,6 @@ init() -> eval(read("(def! not (fn* (a) (if a false true)))"), Env), eval(read("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"), Env), eval(read("(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)))))))"), Env), - eval(read("(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))))))))"), Env), Env. loop(Env) -> diff --git a/erlang/src/step9_try.erl b/erlang/src/step9_try.erl index c35da92f47..8211f76b1d 100644 --- a/erlang/src/step9_try.erl +++ b/erlang/src/step9_try.erl @@ -20,7 +20,6 @@ init() -> eval(read("(def! not (fn* (a) (if a false true)))"), Env), eval(read("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"), Env), eval(read("(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)))))))"), Env), - eval(read("(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))))))))"), Env), Env. loop(Env) -> diff --git a/erlang/src/stepA_mal.erl b/erlang/src/stepA_mal.erl index 4ead8e9b17..d4668fe457 100644 --- a/erlang/src/stepA_mal.erl +++ b/erlang/src/stepA_mal.erl @@ -22,9 +22,6 @@ init() -> eval(read("(def! not (fn* (a) (if a false true)))"), Env), eval(read("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"), Env), eval(read("(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)))))))"), Env), - eval(read("(def! inc (fn* [x] (+ x 1)))"), Env), - eval(read("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"), Env), - eval(read("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (\~condvar \~(first xs)) (if \~condvar \~condvar (or \~@(rest xs)))))))))"), Env), Env. loop(Env) -> diff --git a/es6/step8_macros.mjs b/es6/step8_macros.mjs index 5857c7e2ab..4519515815 100644 --- a/es6/step8_macros.mjs +++ b/es6/step8_macros.mjs @@ -128,7 +128,6 @@ env_set(repl_env, Symbol.for('*ARGV*'), []) 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 (process.argv.length > 2) { env_set(repl_env, Symbol.for('*ARGV*'), process.argv.slice(3)) diff --git a/es6/step9_try.mjs b/es6/step9_try.mjs index 73706c3da8..7cc6e9627f 100644 --- a/es6/step9_try.mjs +++ b/es6/step9_try.mjs @@ -139,7 +139,6 @@ env_set(repl_env, Symbol.for('*ARGV*'), []) 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 (process.argv.length > 2) { env_set(repl_env, Symbol.for('*ARGV*'), process.argv.slice(3)) diff --git a/es6/stepA_mal.mjs b/es6/stepA_mal.mjs index 936a787fb3..4ae066d8bb 100644 --- a/es6/stepA_mal.mjs +++ b/es6/stepA_mal.mjs @@ -140,9 +140,6 @@ REP('(def! *host-language* "ecmascript6")') 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('(def! inc (fn* [x] (+ x 1)))') -REP('(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))') -REP('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))') if (process.argv.length > 2) { env_set(repl_env, Symbol.for('*ARGV*'), process.argv.slice(3)) diff --git a/factor/step8_macros/step8_macros.factor b/factor/step8_macros/step8_macros.factor index 7dda02ed74..330ccb70e6 100755 --- a/factor/step8_macros/step8_macros.factor +++ b/factor/step8_macros/step8_macros.factor @@ -141,7 +141,6 @@ command-line get dup empty? [ rest ] unless "*ARGV*" pick set-at (def! not (fn* (a) (if a false true))) (def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\"))))) (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))))))) -(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)))))))) " string-lines harvest [ REP drop ] each MAIN: main diff --git a/factor/step9_try/step9_try.factor b/factor/step9_try/step9_try.factor index 92fae10371..1a596c8986 100755 --- a/factor/step9_try/step9_try.factor +++ b/factor/step9_try/step9_try.factor @@ -153,7 +153,6 @@ command-line get dup empty? [ rest ] unless "*ARGV*" pick set-at (def! not (fn* (a) (if a false true))) (def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\"))))) (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))))))) -(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)))))))) " string-lines harvest [ REP drop ] each MAIN: main diff --git a/factor/stepA_mal/stepA_mal.factor b/factor/stepA_mal/stepA_mal.factor index 4f964dd304..622bc88938 100755 --- a/factor/stepA_mal/stepA_mal.factor +++ b/factor/stepA_mal/stepA_mal.factor @@ -147,9 +147,6 @@ command-line get dup empty? [ rest ] unless "*ARGV*" pick set-at (def! not (fn* (a) (if a false true))) (def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\"))))) (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))))))) -(def! inc (fn* [x] (+ x 1))) -(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc)))))) -(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs))))))))) " string-lines harvest [ READ repl-env get EVAL drop ] each MAIN: main diff --git a/fantom/src/step8_macros/fan/main.fan b/fantom/src/step8_macros/fan/main.fan index 243295c47f..73310b1e4a 100644 --- a/fantom/src/step8_macros/fan/main.fan +++ b/fantom/src/step8_macros/fan/main.fan @@ -153,7 +153,6 @@ class Main REP("(def! not (fn* (a) (if a false true)))", repl_env) REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - 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))))))))", repl_env) if (!args.isEmpty) { diff --git a/fantom/src/step9_try/fan/main.fan b/fantom/src/step9_try/fan/main.fan index 5a7332ccff..b9f314df61 100644 --- a/fantom/src/step9_try/fan/main.fan +++ b/fantom/src/step9_try/fan/main.fan @@ -165,7 +165,6 @@ class Main REP("(def! not (fn* (a) (if a false true)))", repl_env) REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - 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))))))))", repl_env) if (!args.isEmpty) { diff --git a/fantom/src/stepA_mal/fan/main.fan b/fantom/src/stepA_mal/fan/main.fan index c50e947da4..72587905b8 100644 --- a/fantom/src/stepA_mal/fan/main.fan +++ b/fantom/src/stepA_mal/fan/main.fan @@ -166,9 +166,6 @@ class Main REP("(def! not (fn* (a) (if a false true)))", repl_env) REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - REP("(def! inc (fn* [x] (+ x 1)))", repl_env) - REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env) - REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env) if (!args.isEmpty) { diff --git a/forth/step8_macros.fs b/forth/step8_macros.fs index bbdc4526f4..fffee717f4 100644 --- a/forth/step8_macros.fs +++ b/forth/step8_macros.fs @@ -310,7 +310,6 @@ defcore swap! { argv argc -- val } s\" (def! not (fn* (x) (if x false true)))" rep 2drop s\" (def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" rep 2drop s\" (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 2drop -s\" (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))))))))" rep 2drop : repl ( -- ) begin diff --git a/forth/step9_try.fs b/forth/step9_try.fs index 07ee8b8b3e..d30afadb5a 100644 --- a/forth/step9_try.fs +++ b/forth/step9_try.fs @@ -353,7 +353,6 @@ defcore map ( argv argc -- list ) s\" (def! not (fn* (x) (if x false true)))" rep 2drop s\" (def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" rep 2drop s\" (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 2drop -s\" (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))))))))" rep 2drop : repl ( -- ) begin diff --git a/forth/stepA_mal.fs b/forth/stepA_mal.fs index 994a9a0d26..289794830e 100644 --- a/forth/stepA_mal.fs +++ b/forth/stepA_mal.fs @@ -361,9 +361,6 @@ s\" (def! *host-language* \"forth\")" rep 2drop s\" (def! not (fn* (x) (if x false true)))" rep 2drop s\" (def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" rep 2drop s\" (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 2drop -s\" (def! inc (fn* [x] (+ x 1)))" rep 2drop -s\" (def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" rep 2drop -s\" (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" rep 2drop : repl ( -- ) s\" (println (str \"Mal [\" *host-language* \"]\"))" rep 2drop diff --git a/fsharp/step8_macros.fs b/fsharp/step8_macros.fs index f893f52be7..644114b4ce 100644 --- a/fsharp/step8_macros.fs +++ b/fsharp/step8_macros.fs @@ -186,7 +186,6 @@ module REPL RE env """ (def! not (fn* (a) (if a false true))) (def! load-file (fn* (f) (eval (read-string (slurp f))))) - (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_ ~(first xs)) (if or_ or_ (or ~@(rest xs)))))))) (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))))))) """ |> Seq.iter ignore diff --git a/fsharp/step9_try.fs b/fsharp/step9_try.fs index 6bf6549edf..c001836ba5 100644 --- a/fsharp/step9_try.fs +++ b/fsharp/step9_try.fs @@ -206,7 +206,6 @@ module REPL RE env """ (def! not (fn* (a) (if a false true))) (def! load-file (fn* (f) (eval (read-string (slurp f))))) - (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) `(let* (or_ ~(first xs)) (if or_ or_ (or ~@(rest xs)))))))) (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))))))) """ |> Seq.iter ignore diff --git a/fsharp/stepA_mal.fs b/fsharp/stepA_mal.fs index f2d40c5730..621657b293 100644 --- a/fsharp/stepA_mal.fs +++ b/fsharp/stepA_mal.fs @@ -218,9 +218,6 @@ module REPL (def! not (fn* (a) (if a false true))) (def! load-file (fn* (f) (eval (read-string (slurp f))))) (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))))))) - (def! inc (fn* [x] (+ x 1))) - (def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc)))))) - (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs))))))))) """ |> Seq.iter ignore env diff --git a/gnu-smalltalk/step8_macros.st b/gnu-smalltalk/step8_macros.st index 602e44415d..cd45f84182 100644 --- a/gnu-smalltalk/step8_macros.st +++ b/gnu-smalltalk/step8_macros.st @@ -270,9 +270,7 @@ replEnv set: #'*ARGV*' value: (MALList new: argv). MAL rep: '(def! not (fn* (a) (if a false true)))' env: replEnv. MAL rep: '(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))' env: replEnv. - MAL 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)))))))' env: replEnv. -MAL 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))))))))' env: replEnv. Smalltalk arguments notEmpty ifTrue: [ MAL rep: '(load-file "', Smalltalk arguments first, '")' env: replEnv diff --git a/gnu-smalltalk/step9_try.st b/gnu-smalltalk/step9_try.st index 39022321b0..c5e22fcdc7 100644 --- a/gnu-smalltalk/step9_try.st +++ b/gnu-smalltalk/step9_try.st @@ -291,9 +291,7 @@ replEnv set: #'*ARGV*' value: (MALList new: argv). MAL rep: '(def! not (fn* (a) (if a false true)))' env: replEnv. MAL rep: '(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))' env: replEnv. - MAL 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)))))))' env: replEnv. -MAL 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))))))))' env: replEnv. Smalltalk arguments notEmpty ifTrue: [ MAL rep: '(load-file "', Smalltalk arguments first, '")' env: replEnv diff --git a/gnu-smalltalk/stepA_mal.st b/gnu-smalltalk/stepA_mal.st index dd8db1dadb..67dcd2de51 100644 --- a/gnu-smalltalk/stepA_mal.st +++ b/gnu-smalltalk/stepA_mal.st @@ -292,11 +292,7 @@ replEnv set: #'*host-language*' value: (MALString new: 'smalltalk'). MAL rep: '(def! not (fn* (a) (if a false true)))' env: replEnv. MAL rep: '(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))' env: replEnv. - MAL 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)))))))' env: replEnv. -MAL rep: '(def! inc (fn* [x] (+ x 1)))' env: replEnv. -MAL rep: '(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))' env: replEnv. -MAL rep: '(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))' env: replEnv. Smalltalk arguments notEmpty ifTrue: [ MAL rep: '(load-file "', Smalltalk arguments first, '")' env: replEnv diff --git a/go/src/step8_macros/step8_macros.go b/go/src/step8_macros/step8_macros.go index 4b20938b92..9a8ffa6d3f 100644 --- a/go/src/step8_macros/step8_macros.go +++ b/go/src/step8_macros/step8_macros.go @@ -311,7 +311,6 @@ func main() { 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))))))))") // called with mal script to load and eval if len(os.Args) > 1 { diff --git a/go/src/step9_try/step9_try.go b/go/src/step9_try/step9_try.go index 7902889e2a..52f939a011 100644 --- a/go/src/step9_try/step9_try.go +++ b/go/src/step9_try/step9_try.go @@ -339,7 +339,6 @@ func main() { 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))))))))") // called with mal script to load and eval if len(os.Args) > 1 { diff --git a/go/src/stepA_mal/stepA_mal.go b/go/src/stepA_mal/stepA_mal.go index 60a2908441..223f46d95f 100644 --- a/go/src/stepA_mal/stepA_mal.go +++ b/go/src/stepA_mal/stepA_mal.go @@ -340,9 +340,6 @@ func main() { 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("(def! inc (fn* [x] (+ x 1)))") - rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") - rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") // called with mal script to load and eval if len(os.Args) > 1 { diff --git a/groovy/step8_macros.groovy b/groovy/step8_macros.groovy index 24b1a90af8..8ede17d81a 100644 --- a/groovy/step8_macros.groovy +++ b/groovy/step8_macros.groovy @@ -150,7 +150,6 @@ repl_env.set(new MalSymbol("*ARGV*"), this.args as List) 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 (this.args.size() > 0) { diff --git a/groovy/step9_try.groovy b/groovy/step9_try.groovy index c921bd6d12..bef6e2c77c 100644 --- a/groovy/step9_try.groovy +++ b/groovy/step9_try.groovy @@ -168,7 +168,6 @@ repl_env.set(new MalSymbol("*ARGV*"), this.args as List) 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 (this.args.size() > 0) { diff --git a/groovy/stepA_mal.groovy b/groovy/stepA_mal.groovy index 14c01a3c93..8485e40c92 100644 --- a/groovy/stepA_mal.groovy +++ b/groovy/stepA_mal.groovy @@ -169,10 +169,6 @@ REP("(def! *host-language* \"groovy\")") 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("(def! inc (fn* [x] (+ x 1)))"); -REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); -REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); - if (this.args.size() > 0) { repl_env.set(new MalSymbol("*ARGV*"), this.args.drop(1) as List) diff --git a/guile/core.scm b/guile/core.scm index fca20dbe61..5831bc7d25 100644 --- a/guile/core.scm +++ b/guile/core.scm @@ -150,7 +150,7 @@ ((callable? c) (let ((cc (make-callable ht (callable-unbox c) - (and (hash-table? ht) (hash-ref ht "ismacro")) + #f (callable-closure c)))) cc)) (else diff --git a/guile/step8_macros.scm b/guile/step8_macros.scm index 77f1a1ac5d..39c468953b 100644 --- a/guile/step8_macros.scm +++ b/guile/step8_macros.scm @@ -163,7 +163,6 @@ (EVAL-string "(def! not (fn* (x) (if x false true)))") (EVAL-string "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") (EVAL-string "(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)))))))") -(EVAL-string "(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))))))))") (let ((args (cdr (command-line)))) (cond diff --git a/guile/step9_try.scm b/guile/step9_try.scm index 83b9075184..5aec65b1bd 100644 --- a/guile/step9_try.scm +++ b/guile/step9_try.scm @@ -186,7 +186,6 @@ (EVAL-string "(def! not (fn* (x) (if x false true)))") (EVAL-string "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") (EVAL-string "(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)))))))") -(EVAL-string "(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))))))))") (let ((args (cdr (command-line)))) (cond diff --git a/guile/stepA_mal.scm b/guile/stepA_mal.scm index 17438a9edb..894f14783f 100644 --- a/guile/stepA_mal.scm +++ b/guile/stepA_mal.scm @@ -183,9 +183,6 @@ (EVAL-string "(def! not (fn* (x) (if x false true)))") (EVAL-string "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") (EVAL-string "(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)))))))") -(EVAL-string "(def! inc (fn* [x] (+ x 1)))") -(EVAL-string "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -(EVAL-string "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") (EVAL-string "(def! *host-language* \"guile\")") (let ((args (cdr (command-line)))) diff --git a/haskell/step8_macros.hs b/haskell/step8_macros.hs index 6c0c2ed58f..411b44087b 100644 --- a/haskell/step8_macros.hs +++ b/haskell/step8_macros.hs @@ -202,7 +202,6 @@ main = do re repl_env "(def! not (fn* (a) (if a false true)))" re repl_env "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" re repl_env "(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)))))))" - re repl_env "(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))))))))" case args of script : scriptArgs -> do diff --git a/haskell/step9_try.hs b/haskell/step9_try.hs index c4cc6a5fc9..ab94c996f1 100644 --- a/haskell/step9_try.hs +++ b/haskell/step9_try.hs @@ -213,7 +213,6 @@ main = do re repl_env "(def! not (fn* (a) (if a false true)))" re repl_env "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" re repl_env "(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)))))))" - re repl_env "(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))))))))" case args of script : scriptArgs -> do diff --git a/haskell/stepA_mal.hs b/haskell/stepA_mal.hs index ea903c8d4e..04a44a8e07 100644 --- a/haskell/stepA_mal.hs +++ b/haskell/stepA_mal.hs @@ -214,9 +214,6 @@ main = do re repl_env "(def! not (fn* (a) (if a false true)))" re repl_env "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" re repl_env "(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)))))))" - re repl_env "(def! inc (fn* [x] (+ x 1)))" - re repl_env "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" - re repl_env "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" case args of script : scriptArgs -> do diff --git a/haxe/Step8_macros.hx b/haxe/Step8_macros.hx index dc115bd7d1..0f63a64a52 100644 --- a/haxe/Step8_macros.hx +++ b/haxe/Step8_macros.hx @@ -192,7 +192,6 @@ class Step8_macros { 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 (cmdargs.length > 0) { diff --git a/haxe/Step9_try.hx b/haxe/Step9_try.hx index 07b7f0603e..13aa32082b 100644 --- a/haxe/Step9_try.hx +++ b/haxe/Step9_try.hx @@ -214,7 +214,6 @@ class Step9_try { 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 (cmdargs.length > 0) { diff --git a/haxe/StepA_mal.hx b/haxe/StepA_mal.hx index bf548daa73..958efce120 100644 --- a/haxe/StepA_mal.hx +++ b/haxe/StepA_mal.hx @@ -215,9 +215,6 @@ class StepA_mal { 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("(def! inc (fn* [x] (+ x 1)))"); - rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); - rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); if (cmdargs.length > 0) { diff --git a/hy/step8_macros.hy b/hy/step8_macros.hy index 7297a2a882..5089a20159 100755 --- a/hy/step8_macros.hy +++ b/hy/step8_macros.hy @@ -159,7 +159,6 @@ (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))))))))") (defmain [&rest args] (if (>= (len args) 2) diff --git a/hy/step9_try.hy b/hy/step9_try.hy index d436aa701a..de2c934809 100755 --- a/hy/step9_try.hy +++ b/hy/step9_try.hy @@ -171,7 +171,6 @@ (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))))))))") (defmain [&rest args] (if (>= (len args) 2) diff --git a/hy/stepA_mal.hy b/hy/stepA_mal.hy index f3c7ad6898..42cd81dd2c 100755 --- a/hy/stepA_mal.hy +++ b/hy/stepA_mal.hy @@ -171,9 +171,6 @@ (REP "(def! *host-language* \"Hy\")") (REP "(def! not (fn* [a] (if a false true)))") (REP "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") -(REP "(def! inc (fn* [x] (+ x 1)))") -(REP "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -(REP "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") (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)))))))") (defmain [&rest args] diff --git a/io/step8_macros.io b/io/step8_macros.io index b451019f24..21acdc9f70 100644 --- a/io/step8_macros.io +++ b/io/step8_macros.io @@ -126,7 +126,6 @@ repl_env set(MalSymbol with("*ARGV*"), MalList with(System args slice(2))) RE("(def! not (fn* (a) (if a false true)))") RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") RE("(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)))))))") -RE("(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(System args size > 1, REP("(load-file \"" .. (System args at(1)) .. "\")") diff --git a/io/step9_try.io b/io/step9_try.io index 6c56b10963..c547e2182e 100644 --- a/io/step9_try.io +++ b/io/step9_try.io @@ -137,7 +137,6 @@ repl_env set(MalSymbol with("*ARGV*"), MalList with(System args slice(2))) RE("(def! not (fn* (a) (if a false true)))") RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") RE("(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)))))))") -RE("(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(System args size > 1, REP("(load-file \"" .. (System args at(1)) .. "\")") diff --git a/io/stepA_mal.io b/io/stepA_mal.io index 9dd4a56d1e..55e8911d1f 100644 --- a/io/stepA_mal.io +++ b/io/stepA_mal.io @@ -138,9 +138,6 @@ RE("(def! *host-language* \"io\")") RE("(def! not (fn* (a) (if a false true)))") RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") RE("(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)))))))") -RE("(def! inc (fn* [x] (+ x 1)))") -RE("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if(System args size > 1, REP("(load-file \"" .. (System args at(1)) .. "\")") diff --git a/java/src/main/java/mal/step8_macros.java b/java/src/main/java/mal/step8_macros.java index c2fec4f3a9..24d292080d 100644 --- a/java/src/main/java/mal/step8_macros.java +++ b/java/src/main/java/mal/step8_macros.java @@ -233,7 +233,6 @@ public MalVal apply(MalList args) throws MalThrowable { RE(repl_env, "(def! not (fn* (a) (if a false true)))"); RE(repl_env, "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE(repl_env, "(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)))))))"); - RE(repl_env, "(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))))))))"); Integer fileIdx = 0; if (args.length > 0 && args[0].equals("--raw")) { diff --git a/java/src/main/java/mal/step9_try.java b/java/src/main/java/mal/step9_try.java index 1262bd89fb..ba45f9f9ff 100644 --- a/java/src/main/java/mal/step9_try.java +++ b/java/src/main/java/mal/step9_try.java @@ -259,7 +259,6 @@ public MalVal apply(MalList args) throws MalThrowable { RE(repl_env, "(def! not (fn* (a) (if a false true)))"); RE(repl_env, "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE(repl_env, "(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)))))))"); - RE(repl_env, "(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))))))))"); Integer fileIdx = 0; if (args.length > 0 && args[0].equals("--raw")) { diff --git a/java/src/main/java/mal/stepA_mal.java b/java/src/main/java/mal/stepA_mal.java index 744ccc7e3b..bc964a6937 100644 --- a/java/src/main/java/mal/stepA_mal.java +++ b/java/src/main/java/mal/stepA_mal.java @@ -260,9 +260,6 @@ public MalVal apply(MalList args) throws MalThrowable { RE(repl_env, "(def! not (fn* (a) (if a false true)))"); RE(repl_env, "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"); RE(repl_env, "(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)))))))"); - RE(repl_env, "(def! inc (fn* [x] (+ x 1)))"); - RE(repl_env, "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); - RE(repl_env, "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); Integer fileIdx = 0; if (args.length > 0 && args[0].equals("--raw")) { diff --git a/js/step8_macros.js b/js/step8_macros.js index 54e7a22a5c..fc090fe1dc 100644 --- a/js/step8_macros.js +++ b/js/step8_macros.js @@ -160,7 +160,6 @@ repl_env.set(types._symbol('*ARGV*'), []); 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) { repl_env.set(types._symbol('*ARGV*'), process.argv.slice(3)); diff --git a/js/step9_try.js b/js/step9_try.js index 211e82aed9..fc7c5f9d8f 100644 --- a/js/step9_try.js +++ b/js/step9_try.js @@ -171,7 +171,6 @@ repl_env.set(types._symbol('*ARGV*'), []); 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) { repl_env.set(types._symbol('*ARGV*'), process.argv.slice(3)); diff --git a/js/stepA_mal.js b/js/stepA_mal.js index b997cff4d0..622248c2a1 100644 --- a/js/stepA_mal.js +++ b/js/stepA_mal.js @@ -172,9 +172,6 @@ rep("(def! *host-language* \"javascript\")") 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("(def! inc (fn* [x] (+ x 1)))"); -rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); -rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); if (typeof process !== 'undefined' && process.argv.length > 2) { repl_env.set(types._symbol('*ARGV*'), process.argv.slice(3)); diff --git a/julia/step8_macros.jl b/julia/step8_macros.jl index e7b42c766e..db10a8464b 100755 --- a/julia/step8_macros.jl +++ b/julia/step8_macros.jl @@ -145,7 +145,6 @@ env_set(repl_env, symbol("*ARGV*"), ARGS[2:end]) 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 length(ARGS) > 0 diff --git a/julia/step9_try.jl b/julia/step9_try.jl index 868069a28e..166b4e0e28 100755 --- a/julia/step9_try.jl +++ b/julia/step9_try.jl @@ -163,7 +163,6 @@ env_set(repl_env, symbol("*ARGV*"), ARGS[2:end]) 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 length(ARGS) > 0 diff --git a/julia/stepA_mal.jl b/julia/stepA_mal.jl index 9aed2a2dda..32764a057e 100755 --- a/julia/stepA_mal.jl +++ b/julia/stepA_mal.jl @@ -164,9 +164,6 @@ REP("(def! *host-language* \"julia\")") 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("(def! inc (fn* [x] (+ x 1)))") -REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if length(ARGS) > 0 diff --git a/kotlin/src/mal/step8_macros.kt b/kotlin/src/mal/step8_macros.kt index 929ccfb27c..8d223c5d0a 100644 --- a/kotlin/src/mal/step8_macros.kt +++ b/kotlin/src/mal/step8_macros.kt @@ -155,7 +155,6 @@ fun main(args: Array) { rep("(def! not (fn* (a) (if a false true)))", repl_env) rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - 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))))))))", repl_env) if (args.any()) { rep("(load-file \"${args[0]}\")", repl_env) diff --git a/kotlin/src/mal/step9_try.kt b/kotlin/src/mal/step9_try.kt index 03d44f4e61..722de183e4 100644 --- a/kotlin/src/mal/step9_try.kt +++ b/kotlin/src/mal/step9_try.kt @@ -171,7 +171,6 @@ fun main(args: Array) { rep("(def! not (fn* (a) (if a false true)))", repl_env) rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - 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))))))))", repl_env) if (args.any()) { rep("(load-file \"${args[0]}\")", repl_env) diff --git a/kotlin/src/mal/stepA_mal.kt b/kotlin/src/mal/stepA_mal.kt index 32c3268f4a..93abe0fd83 100644 --- a/kotlin/src/mal/stepA_mal.kt +++ b/kotlin/src/mal/stepA_mal.kt @@ -172,9 +172,6 @@ fun main(args: Array) { rep("(def! not (fn* (a) (if a false true)))", repl_env) rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - rep("(def! inc (fn* [x] (+ x 1)))", repl_env) - rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env) - rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env) if (args.any()) { rep("(load-file \"${args[0]}\")", repl_env) diff --git a/lib/equality.mal b/lib/equality.mal index 8dabb13f60..5f4adaa9be 100644 --- a/lib/equality.mal +++ b/lib/equality.mal @@ -10,30 +10,30 @@ (def! scalar-equal? =) ;; A faster `and` macro which doesn't use `=` internally. -(defmacro! and2 ; boolean +(defmacro! bool-and ; boolean (fn* [& xs] ; interpreted as logical values (if (empty? xs) true - `(if ~(first xs) (and2 ~@(rest xs)) false)))) -(defmacro! or2 ; boolean + `(if ~(first xs) (bool-and ~@(rest xs)) false)))) +(defmacro! bool-or ; boolean (fn* [& xs] ; interpreted as logical values (if (empty? xs) false - `(if ~(first xs) true (or2 ~@(rest xs)))))) + `(if ~(first xs) true (bool-or ~@(rest xs)))))) (def! starts-with? (fn* [a b] - (or2 (empty? a) - (and2 (mal-equal? (first a) (first b)) - (starts-with? (rest a) (rest b)))))) + (bool-or (empty? a) + (bool-and (mal-equal? (first a) (first b)) + (starts-with? (rest a) (rest b)))))) (def! hash-map-vals-equal? (fn* [a b map-keys] - (or2 (empty? map-keys) - (let* [key (first map-keys)] - (and2 (contains? b key) - (mal-equal? (get a key) (get b key)) - (hash-map-vals-equal? a b (rest map-keys))))))) + (bool-or (empty? map-keys) + (let* [key (first map-keys)] + (bool-and (contains? b key) + (mal-equal? (get a key) (get b key)) + (hash-map-vals-equal? a b (rest map-keys))))))) ;; This implements = in pure mal (using only scalar-equal? as native impl) (def! mal-equal? @@ -41,15 +41,15 @@ (cond (sequential? a) - (and2 (sequential? b) - (scalar-equal? (count a) (count b)) - (starts-with? a b)) + (bool-and (sequential? b) + (scalar-equal? (count a) (count b)) + (starts-with? a b)) (map? a) (let* [keys-a (keys a)] - (and2 (map? b) - (scalar-equal? (count keys-a) (count (keys b))) - (hash-map-vals-equal? a b keys-a))) + (bool-and (map? b) + (scalar-equal? (count keys-a) (count (keys b))) + (hash-map-vals-equal? a b keys-a))) true (scalar-equal? a b)))) @@ -57,20 +57,21 @@ (def! hash-map-equality-correct? (fn* [] (try* - (and2 (= {:a 1} {:a 1}) - (not (= {:a 1} {:a 1 :b 2}))) + (bool-and (= {:a 1} {:a 1}) + (not (= {:a 1} {:a 1 :b 2}))) (catch* _ false)))) (def! sequence-equality-correct? (fn* [] (try* - (and2 (= [:a :b] (list :a :b)) - (not (= [:a :b] [:a :b :c]))) + (bool-and (= [:a :b] (list :a :b)) + (not (= [:a :b] [:a :b :c]))) (catch* _ false)))) ;; If the native `=` implementation doesn't support sequences or hash-maps ;; correctly, replace it with the pure mal implementation -(if (not (and2 (hash-map-equality-correct?) (sequence-equality-correct?))) +(if (not (bool-and (hash-map-equality-correct?) + (sequence-equality-correct?))) (do (def! = mal-equal?) (println "equality.mal: Replaced = with pure mal implementation"))) diff --git a/lib/perf.mal b/lib/perf.mal index c01f517706..0025fee93e 100644 --- a/lib/perf.mal +++ b/lib/perf.mal @@ -1,12 +1,14 @@ ;; Mesure performances. +(load-file "../lib/trivial.mal") ; gensym inc + ;; Evaluate an expression, but report the time spent (defmacro! time (fn* (exp) (let* [start (gensym) ret (gensym)] - `(let* [~start (time-ms) - ~ret ~exp] + `(let* (~start (time-ms) + ~ret ~exp) (do (prn (str "Elapsed time: " (- (time-ms) ~start) " msecs")) ~ret))))) @@ -19,7 +21,7 @@ (let* [start (time-ms) _ (fn) elapsed (- (time-ms) start) - iters (+ 1 last-iters) + iters (inc last-iters) new-acc-ms (+ acc-ms elapsed)] ;; (do (prn "new-acc-ms:" new-acc-ms "iters:" iters)) (if (>= new-acc-ms max-ms) diff --git a/lib/test_cascade.mal b/lib/test_cascade.mal index cabe53339d..6494c1f59b 100644 --- a/lib/test_cascade.mal +++ b/lib/test_cascade.mal @@ -1,5 +1,23 @@ ;; Iteration on evaluations interpreted as boolean values. +(load-file "../lib/trivial.mal") ; gensym + +;; `(cond test1 result1 test2 result2 .. testn resultn)` +;; is rewritten (in the step files) as +;; `(if test1 result1 (if test2 result2 (.. (if testn resultn nil))))` +;; It is common that `testn` is `"else"`, `:else`, `true` or similar. + +;; `(or x1 x2 .. xn x)` +;; is almost rewritten as +;; `(if x1 x1 (if x2 x2 (.. (if xn xn x))))` +;; except that each argument is evaluated at most once. +;; Without arguments, returns `nil`. +(defmacro! or (fn* [& xs] + (if (< (count xs) 2) + (first xs) + (let* [r (gensym)] + `(let* (~r ~(first xs)) (if ~r ~r (or ~@(rest xs)))))))) + ;; Conjonction of predicate values (pred x1) and .. and (pred xn) ;; Evaluate `pred x` for each `x` in turn. Return `false` if a result ;; is `nil` or `false`, without evaluating the predicate for the diff --git a/lib/trivial.mal b/lib/trivial.mal index 8c4f6b6b6a..209693fdb0 100644 --- a/lib/trivial.mal +++ b/lib/trivial.mal @@ -1,5 +1,8 @@ ;; Trivial but convenient functions. +;; Integer predecessor (number -> number) +(def! inc (fn* [a] (+ a 1))) + ;; Integer predecessor (number -> number) (def! dec (fn* (a) (- a 1))) @@ -9,4 +12,11 @@ ;; Returns the unchanged argument. (def! identity (fn* (x) x)) +;; Generate a hopefully unique symbol. See section "Plugging the Leaks" +;; of http://www.gigamonkeys.com/book/macros-defining-your-own.html +(def! gensym + (let* [counter (atom 0)] + (fn* [] + (symbol (str "G__" (swap! counter inc)))))) + nil diff --git a/livescript/step8_macros.ls b/livescript/step8_macros.ls index f6da156c60..b5ac57063f 100644 --- a/livescript/step8_macros.ls +++ b/livescript/step8_macros.ls @@ -321,17 +321,6 @@ rep ' (throw "odd number of forms to cond")) (cons \'cond (rest (rest xs)))))))' -# Define or. -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))))))))' - # Parse program arguments. # The first two (exe and core-file) are, respectively, # the interpreter executable (nodejs or lsc) and the diff --git a/livescript/step9_try.ls b/livescript/step9_try.ls index a77686ca1d..abd3b8ecff 100644 --- a/livescript/step9_try.ls +++ b/livescript/step9_try.ls @@ -352,17 +352,6 @@ rep ' (throw "odd number of forms to cond")) (cons \'cond (rest (rest xs)))))))' -# Define or. -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))))))))' - # Parse program arguments. # The first two (exe and core-file) are, respectively, # the interpreter executable (nodejs or lsc) and the diff --git a/livescript/stepA_mal.ls b/livescript/stepA_mal.ls index e6c9561a8d..08fbd81ebc 100644 --- a/livescript/stepA_mal.ls +++ b/livescript/stepA_mal.ls @@ -352,25 +352,6 @@ rep ' (throw "odd number of forms to cond")) (cons \'cond (rest (rest xs)))))))' -rep '(def! inc (fn* [x] (+ x 1)))' - -rep ' -(def! gensym - (let* [counter (atom 0)] - (fn* [] - (symbol (str "G__" (swap! counter inc))))))' - -rep ' -(defmacro! or - (fn* (& xs) - (if (empty? xs) - nil - (if (= 1 (count xs)) - (first xs) - (let* (condvar (gensym)) - `(let* (~condvar ~(first xs)) - (if ~condvar ~condvar (or ~@(rest xs)))))))))' - # Parse program arguments. # The first two (exe and core-file) are, respectively, # the interpreter executable (nodejs or lsc) and the diff --git a/logo/step8_macros.lg b/logo/step8_macros.lg index 885eff3fbd..d45eb8277f 100644 --- a/logo/step8_macros.lg +++ b/logo/step8_macros.lg @@ -201,7 +201,6 @@ ignore env_set :repl_env [symbol *ARGV*] argv_list ignore re "|(def! not (fn* (a) (if a false true)))| ignore re "|(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))| ignore re "|(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)))))))| -ignore re "|(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 not emptyp :command.line [ catch "error [ignore re (word "\(load-file :space_char "\" first :command.line "\"\) )] diff --git a/logo/step9_try.lg b/logo/step9_try.lg index b5e0e7c410..ac02d269e6 100644 --- a/logo/step9_try.lg +++ b/logo/step9_try.lg @@ -220,7 +220,6 @@ ignore env_set :repl_env [symbol *ARGV*] argv_list ignore re "|(def! not (fn* (a) (if a false true)))| ignore re "|(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))| ignore re "|(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)))))))| -ignore re "|(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 not emptyp :command.line [ catch "error [ignore re (word "\(load-file :space_char "\" first :command.line "\"\) )] diff --git a/logo/stepA_mal.lg b/logo/stepA_mal.lg index 6daba153af..6c842fbea4 100644 --- a/logo/stepA_mal.lg +++ b/logo/stepA_mal.lg @@ -221,9 +221,6 @@ ignore re "|(def! *host-language* "logo")| ignore re "|(def! not (fn* (a) (if a false true)))| ignore re "|(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))| ignore re "|(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)))))))| -ignore re "|(def! inc (fn* [x] (+ x 1)))| -ignore re "|(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))| -ignore re "|(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))| if not emptyp :command.line [ catch "error [ignore re (word "\(load-file :space_char "\" first :command.line "\"\) )] diff --git a/lua/step8_macros.lua b/lua/step8_macros.lua index 33538154f9..cb49946b65 100755 --- a/lua/step8_macros.lua +++ b/lua/step8_macros.lua @@ -155,7 +155,6 @@ repl_env:set(types.Symbol:new('*ARGV*'), types.List:new(types.slice(arg,2))) 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 #arg > 0 and arg[1] == "--raw" then readline.raw = true diff --git a/lua/step9_try.lua b/lua/step9_try.lua index 2cb5817155..b9620bfb8c 100755 --- a/lua/step9_try.lua +++ b/lua/step9_try.lua @@ -173,7 +173,6 @@ repl_env:set(types.Symbol:new('*ARGV*'), types.List:new(types.slice(arg,2))) 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))))))))") function print_exception(exc) if exc then diff --git a/lua/stepA_mal.lua b/lua/stepA_mal.lua index dd9ab81d62..47c35ca894 100755 --- a/lua/stepA_mal.lua +++ b/lua/stepA_mal.lua @@ -175,9 +175,6 @@ rep("(def! *host-language* \"lua\")") 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("(def! inc (fn* [x] (+ x 1)))") -rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") function print_exception(exc) if exc then diff --git a/make/step8_macros.mk b/make/step8_macros.mk index 7ee0a94404..310d6fda6a 100644 --- a/make/step8_macros.mk +++ b/make/step8_macros.mk @@ -156,7 +156,6 @@ REPL_ENV := $(call ENV_SET,$(REPL_ENV),*ARGV*,$(_argv)) $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) $(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) $(call do,$(call 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))))))) )) -$(call do,$(call 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)))))))) )) # Load and eval any files specified on the command line $(if $(MAKECMDGOALS),\ diff --git a/make/step9_try.mk b/make/step9_try.mk index 2066795625..46a292dcef 100644 --- a/make/step9_try.mk +++ b/make/step9_try.mk @@ -171,7 +171,6 @@ REPL_ENV := $(call ENV_SET,$(REPL_ENV),*ARGV*,$(_argv)) $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) $(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) $(call do,$(call 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))))))) )) -$(call do,$(call 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)))))))) )) # Load and eval any files specified on the command line $(if $(MAKECMDGOALS),\ diff --git a/make/stepA_mal.mk b/make/stepA_mal.mk index 9c013e10b8..228409930b 100644 --- a/make/stepA_mal.mk +++ b/make/stepA_mal.mk @@ -176,9 +176,6 @@ $(call do,$(call REP, (def! *host-language* "make") )) $(call do,$(call REP, (def! not (fn* (a) (if a false true))) )) $(call do,$(call REP, (def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")"))))) )) $(call do,$(call 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))))))) )) -$(call do,$(call REP, (def! inc (fn* [x] (+ x 1))) )) -$(call do,$(call REP, (def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc)))))) )) -$(call do,$(call REP, (defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs))))))))) )) # Load and eval any files specified on the command line $(if $(MAKECMDGOALS),\ diff --git a/mal/core.mal b/mal/core.mal index 15bcac3ec0..5137f502f4 100644 --- a/mal/core.mal +++ b/mal/core.mal @@ -1,80 +1,76 @@ -(def! _fn? (fn* [x] - (if (fn? x) - (if (get (meta x) "ismacro") - false - true) +(def! _map? (fn* [x] + (if (map? x) + (not (contains? x :__MAL_MACRO__)) false))) -(def! macro? (fn* [x] - (if (fn? x) - (if (get (meta x) "ismacro") - true - false) +(def! _macro? (fn* [x] + (if (map? x) + (contains? x :__MAL_MACRO__) false))) (def! core_ns - [["=" =] - ["throw" throw] - ["nil?" nil?] - ["true?" true?] - ["false?" false?] - ["number?" number?] - ["string?" string?] - ["symbol" symbol] - ["symbol?" symbol?] - ["keyword" keyword] - ["keyword?" keyword?] - ["fn?" _fn?] - ["macro?" macro?] + [['= =] + ['throw throw] + ['nil? nil?] + ['true? true?] + ['false? false?] + ['number? number?] + ['string? string?] + ['symbol symbol] + ['symbol? symbol?] + ['keyword keyword] + ['keyword? keyword?] + ['fn? fn?] + ['macro? _macro?] - ["pr-str" pr-str] - ["str" str] - ["prn" prn] - ["println" println] - ["readline" readline] - ["read-string" read-string] - ["slurp" slurp] - ["<" <] - ["<=" <=] - [">" >] - [">=" >=] - ["+" +] - ["-" -] - ["*" *] - ["/" /] - ["time-ms" time-ms] + ['pr-str pr-str] + ['str str] + ['prn prn] + ['println println] + ['readline readline] + ['read-string read-string] + ['slurp slurp] + ['< <] + ['<= <=] + ['> >] + ['>= >=] + ['+ +] + ['- -] + ['* *] + ['/ /] + ['time-ms time-ms] - ["list" list] - ["list?" list?] - ["vector" vector] - ["vector?" vector?] - ["hash-map" hash-map] - ["map?" map?] - ["assoc" assoc] - ["dissoc" dissoc] - ["get" get] - ["contains?" contains?] - ["keys" keys] - ["vals" vals] + ['list list] + ['list? list?] + ['vector vector] + ['vector? vector?] + ['hash-map hash-map] + ['map? _map?] + ['assoc assoc] + ['dissoc dissoc] + ['get get] + ['contains? contains?] + ['keys keys] + ['vals vals] - ["sequential?" sequential?] - ["cons" cons] - ["concat" concat] - ["nth" nth] - ["first" first] - ["rest" rest] - ["empty?" empty?] - ["count" count] - ["apply" apply] - ["map" map] + ['sequential? sequential?] + ['cons cons] + ['concat concat] + ['nth nth] + ['first first] + ['rest rest] + ['empty? empty?] + ['count count] + ['apply apply] + ['map map] - ["conj" conj] - ["seq" seq] + ['conj conj] + ['seq seq] - ["with-meta" with-meta] - ["meta" meta] - ["atom" atom] - ["atom?" atom?] - ["deref" deref] - ["reset!" reset!] - ["swap!" swap!]]) + ['with-meta with-meta] + ['meta meta] + ['atom atom] + ['atom? atom?] + ['deref deref] + ['reset! reset!] + ['swap! swap!]]) diff --git a/mal/env.mal b/mal/env.mal index bec21c37ea..d0ddee2601 100644 --- a/mal/env.mal +++ b/mal/env.mal @@ -1,29 +1,23 @@ -;; env - (def! bind-env (fn* [env b e] (if (empty? b) env - - (if (= "&" (str (first b))) - (assoc env (str (nth b 1)) e) - - (bind-env (assoc env (str (first b)) (first e)) - (rest b) (rest e)))))) + (let* [b0 (first b)] + (if (= '& b0) + (assoc env (str (nth b 1)) e) + (bind-env (assoc env (str b0) (first e)) (rest b) (rest e))))))) (def! new-env (fn* [& args] (if (<= (count args) 1) (atom {:outer (first args)}) - (atom (bind-env {:outer (first args)} - (nth args 1) (nth args 2)))))) + (atom (apply bind-env {:outer (first args)} (rest args)))))) (def! env-find (fn* [env k] - (let* [ks (str k) - data @env] - (if (contains? data ks) - env - (if (get data :outer) - (env-find (get data :outer) ks) - nil))))) + (if env + (let* [ks (str k) + data @env] + (if (contains? data ks) + env + (env-find (get data :outer) ks)))))) (def! env-get (fn* [env k] (let* [ks (str k) @@ -36,5 +30,3 @@ (do (swap! env assoc (str k) v) v))) - -;;(prn "loaded env.mal") diff --git a/mal/step0_repl.mal b/mal/step0_repl.mal index 723c83c4ea..d4a7be8390 100644 --- a/mal/step0_repl.mal +++ b/mal/step0_repl.mal @@ -3,7 +3,7 @@ strng)) ;; eval -(def! EVAL (fn* [ast env] +(def! EVAL (fn* [ast] ast)) ;; print @@ -11,20 +11,18 @@ ;; repl (def! rep (fn* [strng] - (PRINT (EVAL (READ strng) {})))) + (PRINT (EVAL (READ strng))))) ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) -(def! -main (fn* [& args] - (repl-loop))) -(-main) +;; main +(repl-loop "") diff --git a/mal/step1_read_print.mal b/mal/step1_read_print.mal index 991a745f7d..dd541faa9d 100644 --- a/mal/step1_read_print.mal +++ b/mal/step1_read_print.mal @@ -1,30 +1,28 @@ ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) + ;; eval -(def! EVAL (fn* [ast env] +(def! EVAL (fn* [ast] ast)) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! rep (fn* [strng] - (PRINT (EVAL (READ strng) {})))) + (PRINT (EVAL (READ strng))))) ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) -(def! -main (fn* [& args] - (repl-loop))) -(-main) +;; main +(repl-loop "") diff --git a/mal/step2_eval.mal b/mal/step2_eval.mal index 499ff94e03..995c80dd83 100644 --- a/mal/step2_eval.mal +++ b/mal/step2_eval.mal @@ -1,11 +1,10 @@ ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (let* [res (get env (str ast))] (if res res (throw (str ast " not found")))) @@ -19,25 +18,23 @@ (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast) ) (if (not (list? ast)) (eval-ast ast env) ;; apply list (if (empty? ast) ast - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args))))))) + (let* [el (eval-ast ast env)] + (apply (first el) (rest el))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env {"+" + @@ -48,17 +45,15 @@ (PRINT (EVAL (READ strng) repl-env)))) ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (repl-loop))) -(-main) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(repl-loop "") diff --git a/mal/step3_env.mal b/mal/step3_env.mal index 985e644d9b..d37cb07f77 100644 --- a/mal/step3_env.mal +++ b/mal/step3_env.mal @@ -1,13 +1,12 @@ (load-file "../mal/env.mal") ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (env-get env ast) @@ -20,43 +19,39 @@ (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! LET (fn* [env args] - (if (> (count args) 0) +(def! LET (fn* [env binds form] + (if (empty? binds) + (EVAL form env) (do - (env-set env (nth args 0) (EVAL (nth args 1) env)) - (LET env (rest (rest args))))))) + (env-set env (first binds) (EVAL (nth binds 1) env)) + (LET env (rest (rest binds)) form))))) -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast "/" (keys @env)) ) (if (not (list? ast)) (eval-ast ast env) ;; apply list (let* [a0 (first ast)] (cond - (nil? a0) + (empty? ast) ast (= 'def! a0) (env-set env (nth ast 1) (EVAL (nth ast 2) env)) (= 'let* a0) - (let* [let-env (new-env env)] - (do - (LET let-env (nth ast 1)) - (EVAL (nth ast 2) let-env))) + (LET (new-env env) (nth ast 1) (nth ast 2)) "else" - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args)))))))) + (let* [el (eval-ast ast env)] + (apply (first el) (rest el)))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env (new-env)) @@ -69,17 +64,15 @@ (env-set repl-env "/" /) ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (repl-loop))) -(-main) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(repl-loop "") diff --git a/mal/step4_if_fn_do.mal b/mal/step4_if_fn_do.mal index b72cd83ee1..05297be2bc 100644 --- a/mal/step4_if_fn_do.mal +++ b/mal/step4_if_fn_do.mal @@ -2,13 +2,12 @@ (load-file "../mal/core.mal") ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (env-get env ast) @@ -21,59 +20,52 @@ (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! LET (fn* [env args] - (if (> (count args) 0) +(def! LET (fn* [env binds form] + (if (empty? binds) + (EVAL form env) (do - (env-set env (nth args 0) (EVAL (nth args 1) env)) - (LET env (rest (rest args))))))) + (env-set env (first binds) (EVAL (nth binds 1) env)) + (LET env (rest (rest binds)) form))))) -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast "/" (keys @env)) ) (if (not (list? ast)) (eval-ast ast env) ;; apply list (let* [a0 (first ast)] (cond - (nil? a0) + (empty? ast) ast (= 'def! a0) (env-set env (nth ast 1) (EVAL (nth ast 2) env)) (= 'let* a0) - (let* [let-env (new-env env)] - (do - (LET let-env (nth ast 1)) - (EVAL (nth ast 2) let-env))) + (LET (new-env env) (nth ast 1) (nth ast 2)) (= 'do a0) (let* [el (eval-ast (rest ast) env)] (nth el (- (count el) 1))) (= 'if a0) - (let* [cond (EVAL (nth ast 1) env)] - (if (or (= cond nil) (= cond false)) - (if (> (count ast) 3) - (EVAL (nth ast 3) env) - nil) - (EVAL (nth ast 2) env))) + (if (EVAL (nth ast 1) env) + (EVAL (nth ast 2) env) + (if (> (count ast) 3) + (EVAL (nth ast 3) env))) (= 'fn* a0) - (fn* [& args] - (EVAL (nth ast 2) (new-env env (nth ast 1) args))) + (fn* [& args] (EVAL (nth ast 2) (new-env env (nth ast 1) args))) "else" - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args)))))))) + (let* [el (eval-ast ast env)] + (apply (first el) (rest el)))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env (new-env)) @@ -81,23 +73,21 @@ (PRINT (EVAL (READ strng) repl-env)))) ;; core.mal: defined directly using mal -(map (fn* [data] (env-set repl-env (nth data 0) (nth data 1))) core_ns) +(map (fn* [data] (apply env-set repl-env data)) core_ns) -;; core.mal: defined using the new language itself +;; core.mal: defined using the new language itself (rep "(def! not (fn* [a] (if a false true)))") ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (repl-loop))) -(-main) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(repl-loop "") diff --git a/mal/step6_file.mal b/mal/step6_file.mal index 23df09aa50..fbfeb89789 100644 --- a/mal/step6_file.mal +++ b/mal/step6_file.mal @@ -2,13 +2,12 @@ (load-file "../mal/core.mal") ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (env-get env ast) @@ -21,59 +20,52 @@ (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! LET (fn* [env args] - (if (> (count args) 0) +(def! LET (fn* [env binds form] + (if (empty? binds) + (EVAL form env) (do - (env-set env (nth args 0) (EVAL (nth args 1) env)) - (LET env (rest (rest args))))))) + (env-set env (first binds) (EVAL (nth binds 1) env)) + (LET env (rest (rest binds)) form))))) -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast "/" (keys @env)) ) (if (not (list? ast)) (eval-ast ast env) ;; apply list (let* [a0 (first ast)] (cond - (nil? a0) + (empty? ast) ast (= 'def! a0) (env-set env (nth ast 1) (EVAL (nth ast 2) env)) (= 'let* a0) - (let* [let-env (new-env env)] - (do - (LET let-env (nth ast 1)) - (EVAL (nth ast 2) let-env))) + (LET (new-env env) (nth ast 1) (nth ast 2)) (= 'do a0) (let* [el (eval-ast (rest ast) env)] (nth el (- (count el) 1))) (= 'if a0) - (let* [cond (EVAL (nth ast 1) env)] - (if (or (= cond nil) (= cond false)) - (if (> (count ast) 3) - (EVAL (nth ast 3) env) - nil) - (EVAL (nth ast 2) env))) + (if (EVAL (nth ast 1) env) + (EVAL (nth ast 2) env) + (if (> (count ast) 3) + (EVAL (nth ast 3) env))) (= 'fn* a0) - (fn* [& args] - (EVAL (nth ast 2) (new-env env (nth ast 1) args))) + (fn* [& args] (EVAL (nth ast 2) (new-env env (nth ast 1) args))) "else" - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args)))))))) + (let* [el (eval-ast ast env)] + (apply (first el) (rest el)))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env (new-env)) @@ -81,28 +73,26 @@ (PRINT (EVAL (READ strng) repl-env)))) ;; core.mal: defined directly using mal -(map (fn* [data] (env-set repl-env (nth data 0) (nth data 1))) core_ns) +(map (fn* [data] (apply env-set repl-env data)) core_ns) (env-set repl-env 'eval (fn* [ast] (EVAL ast repl-env))) (env-set repl-env '*ARGV* (rest *ARGV*)) -;; core.mal: defined using the new language itself +;; core.mal: defined using the new language itself (rep "(def! not (fn* [a] (if a false true)))") (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (if (> (count args) 0) - (rep (str "(load-file \"" (first args) "\")")) - (repl-loop)))) -(apply -main *ARGV*) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(if (empty? *ARGV*) + (repl-loop "") + (rep (str "(load-file \"" (first *ARGV*) "\")"))) diff --git a/mal/step7_quote.mal b/mal/step7_quote.mal index 85a742342f..483898b614 100644 --- a/mal/step7_quote.mal +++ b/mal/step7_quote.mal @@ -2,34 +2,30 @@ (load-file "../mal/core.mal") ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval (def! is-pair (fn* [x] (if (sequential? x) - (if (> (count x) 0) - true)))) + (not (empty? x))))) (def! QUASIQUOTE (fn* [ast] - (cond - (not (is-pair ast)) + (if (not (is-pair ast)) (list 'quote ast) + (let* [a0 (first ast)] + (cond + (= 'unquote a0) + (nth ast 1) - (= 'unquote (first ast)) - (nth ast 1) - - (if (is-pair (first ast)) - (if (= 'splice-unquote (first (first ast))) - true)) - (list 'concat (nth (first ast) 1) (QUASIQUOTE (rest ast))) + (if (is-pair a0) (= 'splice-unquote (first a0))) ; `if` means `and` + (list 'concat (nth a0 1) (QUASIQUOTE (rest ast))) - "else" - (list 'cons (QUASIQUOTE (first ast)) (QUASIQUOTE (rest ast)))))) + "else" + (list 'cons (QUASIQUOTE a0) (QUASIQUOTE (rest ast)))))))) -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (env-get env ast) @@ -42,66 +38,58 @@ (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! LET (fn* [env args] - (if (> (count args) 0) +(def! LET (fn* [env binds form] + (if (empty? binds) + (EVAL form env) (do - (env-set env (nth args 0) (EVAL (nth args 1) env)) - (LET env (rest (rest args))))))) + (env-set env (first binds) (EVAL (nth binds 1) env)) + (LET env (rest (rest binds)) form))))) -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast "/" (keys @env)) ) (if (not (list? ast)) (eval-ast ast env) ;; apply list (let* [a0 (first ast)] (cond - (nil? a0) + (empty? ast) ast (= 'def! a0) (env-set env (nth ast 1) (EVAL (nth ast 2) env)) (= 'let* a0) - (let* [let-env (new-env env)] - (do - (LET let-env (nth ast 1)) - (EVAL (nth ast 2) let-env))) + (LET (new-env env) (nth ast 1) (nth ast 2)) (= 'quote a0) (nth ast 1) (= 'quasiquote a0) - (let* [a1 (nth ast 1)] - (EVAL (QUASIQUOTE a1) env)) + (EVAL (QUASIQUOTE (nth ast 1)) env) (= 'do a0) (let* [el (eval-ast (rest ast) env)] (nth el (- (count el) 1))) (= 'if a0) - (let* [cond (EVAL (nth ast 1) env)] - (if (or (= cond nil) (= cond false)) - (if (> (count ast) 3) - (EVAL (nth ast 3) env) - nil) - (EVAL (nth ast 2) env))) + (if (EVAL (nth ast 1) env) + (EVAL (nth ast 2) env) + (if (> (count ast) 3) + (EVAL (nth ast 3) env))) (= 'fn* a0) - (fn* [& args] - (EVAL (nth ast 2) (new-env env (nth ast 1) args))) + (fn* [& args] (EVAL (nth ast 2) (new-env env (nth ast 1) args))) "else" - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args)))))))) + (let* [el (eval-ast ast env)] + (apply (first el) (rest el)))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env (new-env)) @@ -109,28 +97,26 @@ (PRINT (EVAL (READ strng) repl-env)))) ;; core.mal: defined directly using mal -(map (fn* [data] (env-set repl-env (nth data 0) (nth data 1))) core_ns) +(map (fn* [data] (apply env-set repl-env data)) core_ns) (env-set repl-env 'eval (fn* [ast] (EVAL ast repl-env))) (env-set repl-env '*ARGV* (rest *ARGV*)) -;; core.mal: defined using the new language itself +;; core.mal: defined using the new language itself (rep "(def! not (fn* [a] (if a false true)))") (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (if (> (count args) 0) - (rep (str "(load-file \"" (first args) "\")")) - (repl-loop)))) -(apply -main *ARGV*) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(if (empty? *ARGV*) + (repl-loop "") + (rep (str "(load-file \"" (first *ARGV*) "\")"))) diff --git a/mal/step8_macros.mal b/mal/step8_macros.mal index ece64b77bd..0018d4c79a 100644 --- a/mal/step8_macros.mal +++ b/mal/step8_macros.mal @@ -2,50 +2,45 @@ (load-file "../mal/core.mal") ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval (def! is-pair (fn* [x] (if (sequential? x) - (if (> (count x) 0) - true)))) + (not (empty? x))))) (def! QUASIQUOTE (fn* [ast] - (cond - (not (is-pair ast)) + (if (not (is-pair ast)) (list 'quote ast) + (let* [a0 (first ast)] + (cond + (= 'unquote a0) + (nth ast 1) - (= 'unquote (first ast)) - (nth ast 1) - - (if (is-pair (first ast)) - (if (= 'splice-unquote (first (first ast))) - true)) - (list 'concat (nth (first ast) 1) (QUASIQUOTE (rest ast))) + (if (is-pair a0) (= 'splice-unquote (first a0))) ; `if` means `and` + (list 'concat (nth a0 1) (QUASIQUOTE (rest ast))) - "else" - (list 'cons (QUASIQUOTE (first ast)) (QUASIQUOTE (rest ast)))))) + "else" + (list 'cons (QUASIQUOTE a0) (QUASIQUOTE (rest ast)))))))) (def! is-macro-call (fn* [ast env] (if (list? ast) (let* [a0 (first ast)] (if (symbol? a0) (if (env-find env a0) - (let* [m (meta (env-get env a0))] - (if m - (if (get m "ismacro") - true))))))))) + (let* [m (env-get env a0)] + (if (_macro? m) + (get m :__MAL_MACRO__))))))))) (def! MACROEXPAND (fn* [ast env] - (if (is-macro-call ast env) - (let* [mac (env-get env (first ast))] - (MACROEXPAND (apply mac (rest ast)) env)) - ast))) + (let* [m (is-macro-call ast env)] + (if m + (MACROEXPAND (apply m (rest ast)) env) + ast)))) -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (env-get env ast) @@ -53,87 +48,70 @@ (vector? ast) (apply vector (map (fn* [exp] (EVAL exp env)) ast)) - (map? ast) (apply hash-map + (_map? ast) (apply hash-map (apply concat (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! LET (fn* [env args] - (if (> (count args) 0) +(def! LET (fn* [env binds form] + (if (empty? binds) + (EVAL form env) (do - (env-set env (nth args 0) (EVAL (nth args 1) env)) - (LET env (rest (rest args))))))) - -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) - (if (not (list? ast)) - (eval-ast ast env) - - ;; apply list - (let* [ast (MACROEXPAND ast env)] - (if (not (list? ast)) - (eval-ast ast env) - - (let* [a0 (first ast)] - (cond - (nil? a0) - ast - - (= 'def! a0) - (env-set env (nth ast 1) (EVAL (nth ast 2) env)) - - (= 'let* a0) - (let* [let-env (new-env env)] - (do - (LET let-env (nth ast 1)) - (EVAL (nth ast 2) let-env))) - - (= 'quote a0) - (nth ast 1) - - (= 'quasiquote a0) - (let* [a1 (nth ast 1)] - (EVAL (QUASIQUOTE a1) env)) - - (= 'defmacro! a0) - (let* [a1 (nth ast 1) - a2 (nth ast 2) - f (EVAL a2 env) - m (or (meta f) {}) - mac (with-meta f (assoc m "ismacro" true))] - (env-set env a1 mac)) - - (= 'macroexpand a0) - (let* [a1 (nth ast 1)] - (MACROEXPAND a1 env)) - - (= 'do a0) - (let* [el (eval-ast (rest ast) env)] - (nth el (- (count el) 1))) - - (= 'if a0) - (let* [cond (EVAL (nth ast 1) env)] - (if (or (= cond nil) (= cond false)) - (if (> (count ast) 3) - (EVAL (nth ast 3) env) - nil) - (EVAL (nth ast 2) env))) - - (= 'fn* a0) - (fn* [& args] - (EVAL (nth ast 2) (new-env env (nth ast 1) args))) - - "else" - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args)))))))))) + (env-set env (first binds) (EVAL (nth binds 1) env)) + (LET env (rest (rest binds)) form))))) + +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast "/" (keys @env)) ) + (let* [ast (MACROEXPAND ast env)] + (if (not (list? ast)) + (eval-ast ast env) + + ;; apply list + (let* [a0 (first ast)] + (cond + (empty? ast) + ast + + (= 'def! a0) + (env-set env (nth ast 1) (EVAL (nth ast 2) env)) + + (= 'let* a0) + (LET (new-env env) (nth ast 1) (nth ast 2)) + + (= 'quote a0) + (nth ast 1) + + (= 'quasiquote a0) + (EVAL (QUASIQUOTE (nth ast 1)) env) + + (= 'defmacro! a0) + (env-set env (nth ast 1) {:__MAL_MACRO__ (EVAL (nth ast 2) env)}) + + (= 'macroexpand a0) + (MACROEXPAND (nth ast 1) env) + + (= 'do a0) + (let* [el (eval-ast (rest ast) env)] + (nth el (- (count el) 1))) + + (= 'if a0) + (if (EVAL (nth ast 1) env) + (EVAL (nth ast 2) env) + (if (> (count ast) 3) + (EVAL (nth ast 3) env))) + + (= 'fn* a0) + (fn* [& args] (EVAL (nth ast 2) (new-env env (nth ast 1) args))) + + "else" + (let* [el (eval-ast ast env)] + (apply (first el) (rest el))))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env (new-env)) @@ -141,30 +119,27 @@ (PRINT (EVAL (READ strng) repl-env)))) ;; core.mal: defined directly using mal -(map (fn* [data] (env-set repl-env (nth data 0) (nth data 1))) core_ns) +(map (fn* [data] (apply env-set repl-env data)) core_ns) (env-set repl-env 'eval (fn* [ast] (EVAL ast repl-env))) (env-set repl-env '*ARGV* (rest *ARGV*)) -;; core.mal: defined using the new language itself +;; core.mal: defined using the new 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))))))))") ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (if (> (count args) 0) - (rep (str "(load-file \"" (first args) "\")")) - (repl-loop)))) -(apply -main *ARGV*) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(if (empty? *ARGV*) + (repl-loop "") + (rep (str "(load-file \"" (first *ARGV*) "\")"))) diff --git a/mal/step9_try.mal b/mal/step9_try.mal index 2975a5043e..676e93e70a 100644 --- a/mal/step9_try.mal +++ b/mal/step9_try.mal @@ -2,50 +2,45 @@ (load-file "../mal/core.mal") ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval (def! is-pair (fn* [x] (if (sequential? x) - (if (> (count x) 0) - true)))) + (not (empty? x))))) (def! QUASIQUOTE (fn* [ast] - (cond - (not (is-pair ast)) + (if (not (is-pair ast)) (list 'quote ast) + (let* [a0 (first ast)] + (cond + (= 'unquote a0) + (nth ast 1) - (= 'unquote (first ast)) - (nth ast 1) - - (if (is-pair (first ast)) - (if (= 'splice-unquote (first (first ast))) - true)) - (list 'concat (nth (first ast) 1) (QUASIQUOTE (rest ast))) + (if (is-pair a0) (= 'splice-unquote (first a0))) ; `if` means `and` + (list 'concat (nth a0 1) (QUASIQUOTE (rest ast))) - "else" - (list 'cons (QUASIQUOTE (first ast)) (QUASIQUOTE (rest ast)))))) + "else" + (list 'cons (QUASIQUOTE a0) (QUASIQUOTE (rest ast)))))))) (def! is-macro-call (fn* [ast env] (if (list? ast) (let* [a0 (first ast)] (if (symbol? a0) (if (env-find env a0) - (let* [m (meta (env-get env a0))] - (if m - (if (get m "ismacro") - true))))))))) + (let* [m (env-get env a0)] + (if (_macro? m) + (get m :__MAL_MACRO__))))))))) (def! MACROEXPAND (fn* [ast env] - (if (is-macro-call ast env) - (let* [mac (env-get env (first ast))] - (MACROEXPAND (apply mac (rest ast)) env)) - ast))) + (let* [m (is-macro-call ast env)] + (if m + (MACROEXPAND (apply m (rest ast)) env) + ast)))) -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (env-get env ast) @@ -53,99 +48,79 @@ (vector? ast) (apply vector (map (fn* [exp] (EVAL exp env)) ast)) - (map? ast) (apply hash-map + (_map? ast) (apply hash-map (apply concat (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! LET (fn* [env args] - (if (> (count args) 0) +(def! LET (fn* [env binds form] + (if (empty? binds) + (EVAL form env) (do - (env-set env (nth args 0) (EVAL (nth args 1) env)) - (LET env (rest (rest args))))))) - -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) - (if (not (list? ast)) - (eval-ast ast env) - - ;; apply list - (let* [ast (MACROEXPAND ast env)] - (if (not (list? ast)) - (eval-ast ast env) - - (let* [a0 (first ast)] - (cond - (nil? a0) - ast - - (= 'def! a0) - (env-set env (nth ast 1) (EVAL (nth ast 2) env)) - - (= 'let* a0) - (let* [let-env (new-env env)] - (do - (LET let-env (nth ast 1)) - (EVAL (nth ast 2) let-env))) - - (= 'quote a0) - (nth ast 1) - - (= 'quasiquote a0) - (let* [a1 (nth ast 1)] - (EVAL (QUASIQUOTE a1) env)) - - (= 'defmacro! a0) - (let* [a1 (nth ast 1) - a2 (nth ast 2) - f (EVAL a2 env) - m (or (meta f) {}) - mac (with-meta f (assoc m "ismacro" true))] - (env-set env a1 mac)) - - (= 'macroexpand a0) - (let* [a1 (nth ast 1)] - (MACROEXPAND a1 env)) - - (= 'try* a0) - (if (or (< (count ast) 3) - (not (= 'catch* (nth (nth ast 2) 0)))) + (env-set env (first binds) (EVAL (nth binds 1) env)) + (LET env (rest (rest binds)) form))))) + +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast "/" (keys @env)) ) + (let* [ast (MACROEXPAND ast env)] + (if (not (list? ast)) + (eval-ast ast env) + + ;; apply list + (let* [a0 (first ast)] + (cond + (empty? ast) + ast + + (= 'def! a0) + (env-set env (nth ast 1) (EVAL (nth ast 2) env)) + + (= 'let* a0) + (LET (new-env env) (nth ast 1) (nth ast 2)) + + (= 'quote a0) + (nth ast 1) + + (= 'quasiquote a0) + (EVAL (QUASIQUOTE (nth ast 1)) env) + + (= 'defmacro! a0) + (env-set env (nth ast 1) {:__MAL_MACRO__ (EVAL (nth ast 2) env)}) + + (= 'macroexpand a0) + (MACROEXPAND (nth ast 1) env) + + (= 'try* a0) + (if (< (count ast) 3) + (EVAL (nth ast 1) env) + (try* (EVAL (nth ast 1) env) - (try* - (EVAL (nth ast 1) env) - (catch* exc - (EVAL (nth (nth ast 2) 2) - (new-env env - [(nth (nth ast 2)1)] - [exc]))))) - - (= 'do a0) - (let* [el (eval-ast (rest ast) env)] - (nth el (- (count el) 1))) - - (= 'if a0) - (let* [cond (EVAL (nth ast 1) env)] - (if (or (= cond nil) (= cond false)) - (if (> (count ast) 3) - (EVAL (nth ast 3) env) - nil) - (EVAL (nth ast 2) env))) - - (= 'fn* a0) - (fn* [& args] - (EVAL (nth ast 2) (new-env env (nth ast 1) args))) - - "else" - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args)))))))))) + (catch* exc + (let* [a2 (nth ast 2)] + (EVAL (nth a2 2) (new-env env [(nth a2 1)] [exc])))))) + + (= 'do a0) + (let* [el (eval-ast (rest ast) env)] + (nth el (- (count el) 1))) + + (= 'if a0) + (if (EVAL (nth ast 1) env) + (EVAL (nth ast 2) env) + (if (> (count ast) 3) + (EVAL (nth ast 3) env))) + + (= 'fn* a0) + (fn* [& args] (EVAL (nth ast 2) (new-env env (nth ast 1) args))) + + "else" + (let* [el (eval-ast ast env)] + (apply (first el) (rest el))))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env (new-env)) @@ -153,30 +128,27 @@ (PRINT (EVAL (READ strng) repl-env)))) ;; core.mal: defined directly using mal -(map (fn* [data] (env-set repl-env (nth data 0) (nth data 1))) core_ns) +(map (fn* [data] (apply env-set repl-env data)) core_ns) (env-set repl-env 'eval (fn* [ast] (EVAL ast repl-env))) (env-set repl-env '*ARGV* (rest *ARGV*)) -;; core.mal: defined using the new language itself +;; core.mal: defined using the new 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))))))))") ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (if (> (count args) 0) - (rep (str "(load-file \"" (first args) "\")")) - (repl-loop)))) -(apply -main *ARGV*) +(def! repl-loop (fn* [line] + (if line + (do + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(if (empty? *ARGV*) + (repl-loop "") + (rep (str "(load-file \"" (first *ARGV*) "\")"))) diff --git a/mal/stepA_mal.mal b/mal/stepA_mal.mal index 09d7ce8403..26feecf29f 100644 --- a/mal/stepA_mal.mal +++ b/mal/stepA_mal.mal @@ -2,50 +2,45 @@ (load-file "../mal/core.mal") ;; read -(def! READ (fn* [strng] - (read-string strng))) +(def! READ read-string) ;; eval (def! is-pair (fn* [x] (if (sequential? x) - (if (> (count x) 0) - true)))) + (not (empty? x))))) (def! QUASIQUOTE (fn* [ast] - (cond - (not (is-pair ast)) + (if (not (is-pair ast)) (list 'quote ast) + (let* [a0 (first ast)] + (cond + (= 'unquote a0) + (nth ast 1) - (= 'unquote (first ast)) - (nth ast 1) - - (if (is-pair (first ast)) - (if (= 'splice-unquote (first (first ast))) - true)) - (list 'concat (nth (first ast) 1) (QUASIQUOTE (rest ast))) + (if (is-pair a0) (= 'splice-unquote (first a0))) ; `if` means `and` + (list 'concat (nth a0 1) (QUASIQUOTE (rest ast))) - "else" - (list 'cons (QUASIQUOTE (first ast)) (QUASIQUOTE (rest ast)))))) + "else" + (list 'cons (QUASIQUOTE a0) (QUASIQUOTE (rest ast)))))))) (def! is-macro-call (fn* [ast env] (if (list? ast) (let* [a0 (first ast)] (if (symbol? a0) (if (env-find env a0) - (let* [m (meta (env-get env a0))] - (if m - (if (get m "ismacro") - true))))))))) + (let* [m (env-get env a0)] + (if (_macro? m) + (get m :__MAL_MACRO__))))))))) (def! MACROEXPAND (fn* [ast env] - (if (is-macro-call ast env) - (let* [mac (env-get env (first ast))] - (MACROEXPAND (apply mac (rest ast)) env)) - ast))) + (let* [m (is-macro-call ast env)] + (if m + (MACROEXPAND (apply m (rest ast)) env) + ast)))) -(def! eval-ast (fn* [ast env] (do - ;;(do (prn "eval-ast" ast "/" (keys env)) ) +(def! eval-ast (fn* [ast env] + ;; (do (prn "eval-ast" ast "/" (keys env)) ) (cond (symbol? ast) (env-get env ast) @@ -53,99 +48,79 @@ (vector? ast) (apply vector (map (fn* [exp] (EVAL exp env)) ast)) - (map? ast) (apply hash-map + (_map? ast) (apply hash-map (apply concat (map (fn* [k] [k (EVAL (get ast k) env)]) (keys ast)))) - "else" ast)))) + "else" ast))) -(def! LET (fn* [env args] - (if (> (count args) 0) +(def! LET (fn* [env binds form] + (if (empty? binds) + (EVAL form env) (do - (env-set env (nth args 0) (EVAL (nth args 1) env)) - (LET env (rest (rest args))))))) - -(def! EVAL (fn* [ast env] (do - ;;(do (prn "EVAL" ast "/" (keys @env)) ) - (if (not (list? ast)) - (eval-ast ast env) - - ;; apply list - (let* [ast (MACROEXPAND ast env)] - (if (not (list? ast)) - (eval-ast ast env) - - (let* [a0 (first ast)] - (cond - (nil? a0) - ast - - (= 'def! a0) - (env-set env (nth ast 1) (EVAL (nth ast 2) env)) - - (= 'let* a0) - (let* [let-env (new-env env)] - (do - (LET let-env (nth ast 1)) - (EVAL (nth ast 2) let-env))) - - (= 'quote a0) - (nth ast 1) - - (= 'quasiquote a0) - (let* [a1 (nth ast 1)] - (EVAL (QUASIQUOTE a1) env)) - - (= 'defmacro! a0) - (let* [a1 (nth ast 1) - a2 (nth ast 2) - f (EVAL a2 env) - m (or (meta f) {}) - mac (with-meta f (assoc m "ismacro" true))] - (env-set env a1 mac)) - - (= 'macroexpand a0) - (let* [a1 (nth ast 1)] - (MACROEXPAND a1 env)) - - (= 'try* a0) - (if (or (< (count ast) 3) - (not (= 'catch* (nth (nth ast 2) 0)))) + (env-set env (first binds) (EVAL (nth binds 1) env)) + (LET env (rest (rest binds)) form))))) + +(def! EVAL (fn* [ast env] + ;; (do (prn "EVAL" ast "/" (keys @env)) ) + (let* [ast (MACROEXPAND ast env)] + (if (not (list? ast)) + (eval-ast ast env) + + ;; apply list + (let* [a0 (first ast)] + (cond + (empty? ast) + ast + + (= 'def! a0) + (env-set env (nth ast 1) (EVAL (nth ast 2) env)) + + (= 'let* a0) + (LET (new-env env) (nth ast 1) (nth ast 2)) + + (= 'quote a0) + (nth ast 1) + + (= 'quasiquote a0) + (EVAL (QUASIQUOTE (nth ast 1)) env) + + (= 'defmacro! a0) + (env-set env (nth ast 1) {:__MAL_MACRO__ (EVAL (nth ast 2) env)}) + + (= 'macroexpand a0) + (MACROEXPAND (nth ast 1) env) + + (= 'try* a0) + (if (< (count ast) 3) + (EVAL (nth ast 1) env) + (try* (EVAL (nth ast 1) env) - (try* - (EVAL (nth ast 1) env) - (catch* exc - (EVAL (nth (nth ast 2) 2) - (new-env env - [(nth (nth ast 2)1)] - [exc]))))) - - (= 'do a0) - (let* [el (eval-ast (rest ast) env)] - (nth el (- (count el) 1))) - - (= 'if a0) - (let* [cond (EVAL (nth ast 1) env)] - (if (or (= cond nil) (= cond false)) - (if (> (count ast) 3) - (EVAL (nth ast 3) env) - nil) - (EVAL (nth ast 2) env))) - - (= 'fn* a0) - (fn* [& args] - (EVAL (nth ast 2) (new-env env (nth ast 1) args))) - - "else" - (let* [el (eval-ast ast env) - f (first el) - args (rest el)] - (apply f args)))))))))) + (catch* exc + (let* [a2 (nth ast 2)] + (EVAL (nth a2 2) (new-env env [(nth a2 1)] [exc])))))) + + (= 'do a0) + (let* [el (eval-ast (rest ast) env)] + (nth el (- (count el) 1))) + + (= 'if a0) + (if (EVAL (nth ast 1) env) + (EVAL (nth ast 2) env) + (if (> (count ast) 3) + (EVAL (nth ast 3) env))) + + (= 'fn* a0) + (fn* [& args] (EVAL (nth ast 2) (new-env env (nth ast 1) args))) + + "else" + (let* [el (eval-ast ast env)] + (apply (first el) (rest el))))))))) ;; print -(def! PRINT (fn* [exp] (pr-str exp))) +(def! PRINT pr-str) ;; repl (def! repl-env (new-env)) @@ -153,35 +128,28 @@ (PRINT (EVAL (READ strng) repl-env)))) ;; core.mal: defined directly using mal -(map (fn* [data] (env-set repl-env (nth data 0) (nth data 1))) core_ns) +(map (fn* [data] (apply env-set repl-env data)) core_ns) (env-set repl-env 'eval (fn* [ast] (EVAL ast repl-env))) (env-set repl-env '*ARGV* (rest *ARGV*)) -;; core.mal: defined using the new language itself +;; core.mal: defined using the new language itself (rep (str "(def! *host-language* \"" *host-language* "-mal\")")) (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 "(def! inc (fn* [x] (+ x 1)))") -(rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") ;; repl loop -(def! repl-loop (fn* [] - (let* [line (readline "mal-user> ")] - (if line - (do - (if (not (= "" line)) - (try* - (println (rep line)) - (catch* exc - (println "Uncaught exception:" exc)))) - (repl-loop)))))) - -(def! -main (fn* [& args] - (if (> (count args) 0) - (rep (str "(load-file \"" (first args) "\")")) +(def! repl-loop (fn* [line] + (if line (do - (rep "(println (str \"Mal [\" *host-language* \"]\"))") - (repl-loop))))) -(apply -main *ARGV*) + (if (not (= "" line)) + (try* + (println (rep line)) + (catch* exc + (println "Uncaught exception:" exc)))) + (repl-loop (readline "mal-user> ")))))) + +;; main +(if (empty? *ARGV*) + (repl-loop "(println (str \"Mal [\" *host-language* \"]\"))") + (rep (str "(load-file \"" (first *ARGV*) "\")"))) diff --git a/matlab/step8_macros.m b/matlab/step8_macros.m index 7e0b46ab1b..db63826236 100644 --- a/matlab/step8_macros.m +++ b/matlab/step8_macros.m @@ -184,7 +184,6 @@ function main(args) rep('(def! not (fn* (a) (if a false true)))', repl_env); rep('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))"', repl_env); 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)))))))', repl_env); - 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))))))))', repl_env); if ~isempty(args) rep(sprintf('(load-file "%s")', args{1}), repl_env); diff --git a/matlab/step9_try.m b/matlab/step9_try.m index da6447a799..a24d2a5de3 100644 --- a/matlab/step9_try.m +++ b/matlab/step9_try.m @@ -208,7 +208,6 @@ function main(args) rep('(def! not (fn* (a) (if a false true)))', repl_env); rep('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))"', repl_env); 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)))))))', repl_env); - 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))))))))', repl_env); if ~isempty(args) rep(sprintf('(load-file "%s")', args{1}), repl_env); diff --git a/matlab/stepA_mal.m b/matlab/stepA_mal.m index 67e6bf564e..a882cfad73 100644 --- a/matlab/stepA_mal.m +++ b/matlab/stepA_mal.m @@ -209,9 +209,6 @@ function main(args) rep('(def! not (fn* (a) (if a false true)))', repl_env); rep('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))"', repl_env); 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)))))))', repl_env); - rep('(def! inc (fn* [x] (+ x 1)))', repl_env); - rep('(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))', repl_env); - rep('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))', repl_env); if ~isempty(args) rep(sprintf('(load-file "%s")', args{1}), repl_env); diff --git a/miniMAL/step8_macros.json b/miniMAL/step8_macros.json index b0b894d6e4..418806d155 100644 --- a/miniMAL/step8_macros.json +++ b/miniMAL/step8_macros.json @@ -152,7 +152,6 @@ ["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", ["not", ["empty?", "ARGS"]], ["rep", ["str", ["`", "(load-file \""], ["get", "ARGS", 0], ["`", "\")"]]], diff --git a/miniMAL/step9_try.json b/miniMAL/step9_try.json index 8b05eb8d3b..c57a186872 100644 --- a/miniMAL/step9_try.json +++ b/miniMAL/step9_try.json @@ -165,7 +165,6 @@ ["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", ["not", ["empty?", "ARGS"]], ["rep", ["str", ["`", "(load-file \""], ["get", "ARGS", 0], ["`", "\")"]]], diff --git a/miniMAL/stepA_mal.json b/miniMAL/stepA_mal.json index 401fa1ef3b..f70285357a 100644 --- a/miniMAL/stepA_mal.json +++ b/miniMAL/stepA_mal.json @@ -166,9 +166,6 @@ ["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", ["`", "(def! inc (fn* [x] (+ x 1)))"]], -["rep", ["`", "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"]], -["rep", ["`", "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"]], ["if", ["not", ["empty?", "ARGS"]], ["rep", ["str", ["`", "(load-file \""], ["get", "ARGS", 0], ["`", "\")"]]], diff --git a/nasm/step8_macros.asm b/nasm/step8_macros.asm index 04723181ae..06bc91675c 100644 --- a/nasm/step8_macros.asm +++ b/nasm/step8_macros.asm @@ -74,7 +74,6 @@ section .data (def! not (fn* (a) (if a false true))) \ (def! load-file (fn* (f) (eval (read-string (str ",34,"(do",34," (slurp f) ",34,")",34," ))))) \ (defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw ",34,"odd number of forms to cond",34,")) (cons 'cond (rest (rest xs))))))) \ -(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)))))))) \ )" ;; Command to run, appending the name of the script to run diff --git a/nasm/step9_try.asm b/nasm/step9_try.asm index 8f2ffbccef..a92b03e51b 100644 --- a/nasm/step9_try.asm +++ b/nasm/step9_try.asm @@ -80,7 +80,6 @@ section .data (def! not (fn* (a) (if a false true))) \ (def! load-file (fn* (f) (eval (read-string (str ",34,"(do",34," (slurp f) ",34,")",34," ))))) \ (defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw ",34,"odd number of forms to cond",34,")) (cons 'cond (rest (rest xs))))))) \ -(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)))))))) \ )" ;; Command to run, appending the name of the script to run diff --git a/nasm/stepA_mal.asm b/nasm/stepA_mal.asm index a574177a1b..4cdf8236b3 100644 --- a/nasm/stepA_mal.asm +++ b/nasm/stepA_mal.asm @@ -80,9 +80,6 @@ section .data (def! not (fn* (a) (if a false true))) \ (def! load-file (fn* (f) (eval (read-string (str ",34,"(do",34," (slurp f) ",34,")",34," ))))) \ (defmacro! cond (fn* (& xs) (if (> (count xs) 0) (list 'if (first xs) (if (> (count xs) 1) (nth xs 1) (throw ",34,"odd number of forms to cond",34,")) (cons 'cond (rest (rest xs))))))) \ -(def! inc (fn* [x] (+ x 1))) \ -(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str ",34,"G__",34," (swap! counter inc)))))) \ -(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)))))))) \ (def! *host-language* ",34,"nasm",34,")\ (def! conj nil)\ )" diff --git a/nim/step8_macros.nim b/nim/step8_macros.nim index 6de153b2a6..0e22bd70f0 100644 --- a/nim/step8_macros.nim +++ b/nim/step8_macros.nim @@ -155,7 +155,6 @@ proc rep(str: string): string {.discardable.} = 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 paramCount() >= 1: rep "(load-file \"" & paramStr(1) & "\")" diff --git a/nim/step9_try.nim b/nim/step9_try.nim index 314a42c9a2..f32d8d5115 100644 --- a/nim/step9_try.nim +++ b/nim/step9_try.nim @@ -174,7 +174,6 @@ proc rep(str: string): string {.discardable.} = 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 paramCount() >= 1: rep "(load-file \"" & paramStr(1) & "\")" diff --git a/nim/stepA_mal.nim b/nim/stepA_mal.nim index 92e84a8e02..bf47e2ee70 100644 --- a/nim/stepA_mal.nim +++ b/nim/stepA_mal.nim @@ -174,9 +174,6 @@ proc rep(str: string): string {.discardable.} = 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 "(def! inc (fn* [x] (+ x 1)))" -rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" -rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" rep "(def! *host-language* \"nim\")" if paramCount() >= 1: diff --git a/objc/step8_macros.m b/objc/step8_macros.m index 5c3f69e922..00e138c669 100644 --- a/objc/step8_macros.m +++ b/objc/step8_macros.m @@ -206,7 +206,6 @@ int main () { REP(@"(def! not (fn* (a) (if a false true)))", repl_env); REP(@"(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env); 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)))))))", repl_env); - 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))))))))", repl_env); if ([args count] > 1) { diff --git a/objc/step9_try.m b/objc/step9_try.m index 23fe89f0c5..5b4d278c9e 100644 --- a/objc/step9_try.m +++ b/objc/step9_try.m @@ -225,7 +225,6 @@ int main () { REP(@"(def! not (fn* (a) (if a false true)))", repl_env); REP(@"(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env); 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)))))))", repl_env); - 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))))))))", repl_env); if ([args count] > 1) { diff --git a/objc/stepA_mal.m b/objc/stepA_mal.m index 6b68810445..fe21e1ca5d 100644 --- a/objc/stepA_mal.m +++ b/objc/stepA_mal.m @@ -226,9 +226,6 @@ int main () { REP(@"(def! not (fn* (a) (if a false true)))", repl_env); REP(@"(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env); 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)))))))", repl_env); - REP(@"(def! inc (fn* [x] (+ x 1)))", repl_env); - REP(@"(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env); - REP(@"(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env); if ([args count] > 1) { diff --git a/objpascal/step8_macros.pas b/objpascal/step8_macros.pas index a0d9dba6fd..e814663e10 100644 --- a/objpascal/step8_macros.pas +++ b/objpascal/step8_macros.pas @@ -291,7 +291,6 @@ function do_eval(Args : TMalArray) : TMal; 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 ParamCount >= 1 then diff --git a/objpascal/step9_try.pas b/objpascal/step9_try.pas index d8c5960f64..c93dbef454 100644 --- a/objpascal/step9_try.pas +++ b/objpascal/step9_try.pas @@ -313,7 +313,6 @@ function do_eval(Args : TMalArray) : TMal; 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 ParamCount >= 1 then diff --git a/objpascal/stepA_mal.pas b/objpascal/stepA_mal.pas index f77d0def30..f71b8fa716 100644 --- a/objpascal/stepA_mal.pas +++ b/objpascal/stepA_mal.pas @@ -315,9 +315,6 @@ function do_eval(Args : TMalArray) : TMal; 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('(def! inc (fn* [x] (+ x 1)))'); - REP('(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))'); - REP('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))'); if ParamCount >= 1 then diff --git a/ocaml/step8_macros.ml b/ocaml/step8_macros.ml index 92ee6308d5..8b24abff81 100644 --- a/ocaml/step8_macros.ml +++ b/ocaml/step8_macros.ml @@ -122,7 +122,6 @@ let rec main = ignore (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" repl_env); ignore (rep "(def! not (fn* (a) (if a false true)))" repl_env); ignore (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)))))))" repl_env); - ignore (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))))))))" repl_env); if Array.length Sys.argv > 1 then ignore (rep ("(load-file \"" ^ Sys.argv.(1) ^ "\")") repl_env) diff --git a/ocaml/step9_try.ml b/ocaml/step9_try.ml index daea9d8eaf..7557d82a33 100644 --- a/ocaml/step9_try.ml +++ b/ocaml/step9_try.ml @@ -136,7 +136,6 @@ let rec main = ignore (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" repl_env); ignore (rep "(def! not (fn* (a) (if a false true)))" repl_env); ignore (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)))))))" repl_env); - ignore (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))))))))" repl_env); if Array.length Sys.argv > 1 then try diff --git a/ocaml/stepA_mal.ml b/ocaml/stepA_mal.ml index e1e42b2932..41624214a8 100644 --- a/ocaml/stepA_mal.ml +++ b/ocaml/stepA_mal.ml @@ -137,9 +137,6 @@ let rec main = ignore (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" repl_env); ignore (rep "(def! not (fn* (a) (if a false true)))" repl_env); ignore (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)))))))" repl_env); - ignore (rep "(def! inc (fn* [x] (+ x 1)))" repl_env); - ignore (rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" repl_env); - ignore (rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" repl_env); if Array.length Sys.argv > 1 then try diff --git a/perl/step8_macros.pl b/perl/step8_macros.pl index 62b4723c17..3c8826ca26 100644 --- a/perl/step8_macros.pl +++ b/perl/step8_macros.pl @@ -198,7 +198,6 @@ sub REP { 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 (scalar(@ARGV) > 0 && $ARGV[0] eq "--raw") { diff --git a/perl/step9_try.pl b/perl/step9_try.pl index 17ce2d4d1b..2eee047060 100644 --- a/perl/step9_try.pl +++ b/perl/step9_try.pl @@ -226,7 +226,6 @@ sub REP { 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 (scalar(@ARGV) > 0 && $ARGV[0] eq "--raw") { diff --git a/perl/stepA_mal.pl b/perl/stepA_mal.pl index 991c988b78..2071c65630 100644 --- a/perl/stepA_mal.pl +++ b/perl/stepA_mal.pl @@ -230,10 +230,6 @@ sub REP { 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("(def! inc (fn* [x] (+ x 1)))"); -REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); -REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); - if (scalar(@ARGV) > 0 && $ARGV[0] eq "--raw") { set_rl_mode("raw"); diff --git a/perl6/step8_macros.pl b/perl6/step8_macros.pl index 39491593fc..375388c860 100644 --- a/perl6/step8_macros.pl +++ b/perl6/step8_macros.pl @@ -127,7 +127,6 @@ ($source_file?, *@args) rep(q{(def! not (fn* (a) (if a false true)))}); rep(q{(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))}); rep(q{(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(q{(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 ($source_file.defined) { rep("(load-file \"$source_file\")"); diff --git a/perl6/step9_try.pl b/perl6/step9_try.pl index 23615889f3..6ce2812981 100644 --- a/perl6/step9_try.pl +++ b/perl6/step9_try.pl @@ -137,7 +137,6 @@ ($source_file?, *@args) rep(q{(def! not (fn* (a) (if a false true)))}); rep(q{(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))}); rep(q{(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(q{(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 ($source_file.defined) { rep("(load-file \"$source_file\")"); diff --git a/perl6/stepA_mal.pl b/perl6/stepA_mal.pl index 2f558232ed..c70a96a6f4 100644 --- a/perl6/stepA_mal.pl +++ b/perl6/stepA_mal.pl @@ -138,9 +138,6 @@ ($source_file?, *@args) rep(q{(def! not (fn* (a) (if a false true)))}); rep(q{(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))}); rep(q{(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(q{(def! inc (fn* [x] (+ x 1)))}); - rep(q{(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))}); - rep(q{(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))}); if ($source_file.defined) { rep("(load-file \"$source_file\")"); diff --git a/php/step8_macros.php b/php/step8_macros.php index 0537d61b26..81ab58b451 100644 --- a/php/step8_macros.php +++ b/php/step8_macros.php @@ -174,7 +174,6 @@ function rep($str) { 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 (count($argv) > 1) { rep('(load-file "' . $argv[1] . '")'); diff --git a/php/step9_try.php b/php/step9_try.php index 7f87f1b706..323ec3cee0 100644 --- a/php/step9_try.php +++ b/php/step9_try.php @@ -192,7 +192,6 @@ function rep($str) { 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 (count($argv) > 1) { rep('(load-file "' . $argv[1] . '")'); diff --git a/php/stepA_mal.php b/php/stepA_mal.php index c0cb0d48fc..dc89ab7d24 100644 --- a/php/stepA_mal.php +++ b/php/stepA_mal.php @@ -201,9 +201,6 @@ function rep($str) { 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("(def! inc (fn* [x] (+ x 1)))"); -rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); -rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); // run mal file if (count($argv) > 1) { diff --git a/picolisp/step8_macros.l b/picolisp/step8_macros.l index 8bef4bb0b3..b1445d8623 100644 --- a/picolisp/step8_macros.l +++ b/picolisp/step8_macros.l @@ -131,7 +131,7 @@ (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))))))))") + (load-history ".mal_history") diff --git a/picolisp/step9_try.l b/picolisp/step9_try.l index c5e42d438f..74fe8c273e 100644 --- a/picolisp/step9_try.l +++ b/picolisp/step9_try.l @@ -144,7 +144,6 @@ (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))))))))") (load-history ".mal_history") diff --git a/picolisp/stepA_mal.l b/picolisp/stepA_mal.l index 629562fdde..94b5fd2f87 100644 --- a/picolisp/stepA_mal.l +++ b/picolisp/stepA_mal.l @@ -146,10 +146,6 @@ (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 "(def! inc (fn* [x] (+ x 1)))") -(rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") - (load-history ".mal_history") (if (argv) diff --git a/plpgsql/step8_macros.sql b/plpgsql/step8_macros.sql index c89acfdf5d..fe935af7c3 100644 --- a/plpgsql/step8_macros.sql +++ b/plpgsql/step8_macros.sql @@ -295,7 +295,6 @@ SELECT envs.vset(0, '*ARGV*', mal.READ('()')) \g '/dev/null' SELECT mal.REP('(def! not (fn* (a) (if a false true)))') \g '/dev/null' SELECT mal.REP('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))') \g '/dev/null' SELECT mal.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)))))))') \g '/dev/null' -SELECT mal.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))))))))') \g '/dev/null' CREATE FUNCTION mal.MAIN(pwd varchar, argstring varchar DEFAULT NULL) RETURNS integer AS $$ diff --git a/plpgsql/step9_try.sql b/plpgsql/step9_try.sql index 291cdaac1e..d3623bd2a0 100644 --- a/plpgsql/step9_try.sql +++ b/plpgsql/step9_try.sql @@ -314,7 +314,6 @@ SELECT envs.vset(0, '*ARGV*', mal.READ('()')) \g '/dev/null' SELECT mal.REP('(def! not (fn* (a) (if a false true)))') \g '/dev/null' SELECT mal.REP('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))') \g '/dev/null' SELECT mal.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)))))))') \g '/dev/null' -SELECT mal.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))))))))') \g '/dev/null' CREATE FUNCTION mal.MAIN(pwd varchar, argstring varchar DEFAULT NULL) RETURNS integer AS $$ diff --git a/plpgsql/stepA_mal.sql b/plpgsql/stepA_mal.sql index 448d812ee6..eb44d4f428 100644 --- a/plpgsql/stepA_mal.sql +++ b/plpgsql/stepA_mal.sql @@ -315,9 +315,6 @@ SELECT mal.REP('(def! *host-language* "plpqsql")') \g '/dev/null' SELECT mal.REP('(def! not (fn* (a) (if a false true)))') \g '/dev/null' SELECT mal.REP('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))') \g '/dev/null' SELECT mal.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)))))))') \g '/dev/null' -SELECT mal.REP('(def! inc (fn* [x] (+ x 1)))') \g '/dev/null' -SELECT mal.REP('(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))') \g '/dev/null' -SELECT mal.REP('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))') \g '/dev/null' CREATE FUNCTION mal.MAIN(pwd varchar, argstring varchar DEFAULT NULL) RETURNS integer AS $$ diff --git a/plsql/step8_macros.sql b/plsql/step8_macros.sql index c05b10a941..cee72aab74 100644 --- a/plsql/step8_macros.sql +++ b/plsql/step8_macros.sql @@ -325,7 +325,6 @@ BEGIN line := REP('(def! not (fn* (a) (if a false true)))'); line := REP('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))'); line := 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)))))))'); - line := 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 argv.COUNT() > 0 THEN BEGIN diff --git a/plsql/step9_try.sql b/plsql/step9_try.sql index d69eee379b..2e2bb521b5 100644 --- a/plsql/step9_try.sql +++ b/plsql/step9_try.sql @@ -411,7 +411,6 @@ BEGIN line := REP('(def! not (fn* (a) (if a false true)))'); line := REP('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))'); line := 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)))))))'); - line := 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 argv.COUNT() > 0 THEN BEGIN diff --git a/plsql/stepA_mal.sql b/plsql/stepA_mal.sql index 6c5f6c9eae..9df1750d13 100644 --- a/plsql/stepA_mal.sql +++ b/plsql/stepA_mal.sql @@ -412,9 +412,6 @@ BEGIN line := REP('(def! not (fn* (a) (if a false true)))'); line := REP('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))'); line := 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)))))))'); - line := REP('(def! inc (fn* [x] (+ x 1)))'); - line := REP('(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))'); - line := REP('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))'); IF argv.COUNT() > 0 THEN BEGIN diff --git a/powershell/step8_macros.ps1 b/powershell/step8_macros.ps1 index 295c91bd02..243131f326 100644 --- a/powershell/step8_macros.ps1 +++ b/powershell/step8_macros.ps1 @@ -171,7 +171,6 @@ $_ = $repl_env.set((new-symbol "*ARGV*"), (new-list $args[1..$args.Count])) $_ = 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 ($args.Count -gt 0) { diff --git a/powershell/step9_try.ps1 b/powershell/step9_try.ps1 index e913d14f73..e2f8f07f83 100644 --- a/powershell/step9_try.ps1 +++ b/powershell/step9_try.ps1 @@ -187,7 +187,6 @@ $_ = $repl_env.set((new-symbol "*ARGV*"), (new-list $args[1..$args.Count])) $_ = 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 ($args.Count -gt 0) { diff --git a/powershell/stepA_mal.ps1 b/powershell/stepA_mal.ps1 index 1e616e79d5..be46d061e0 100644 --- a/powershell/stepA_mal.ps1 +++ b/powershell/stepA_mal.ps1 @@ -188,9 +188,6 @@ $_ = REP('(def! *host-language* "powershell")') $_ = 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('(def! inc (fn* [x] (+ x 1)))') -$_ = REP('(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))') -$_ = REP('(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))') if ($args.Count -gt 0) { diff --git a/process/guide.md b/process/guide.md index 0e9c571b57..9aa8a15baf 100644 --- a/process/guide.md +++ b/process/guide.md @@ -1331,15 +1331,15 @@ implementation. Let us continue! * `rest`: this function takes a list (or vector) as its argument and returns a new list containing all the elements except the first. -* In the main program, use the `rep` function to define two new - control structures macros. Here are the string arguments for `rep` - to define these macros: - * `cond`: "(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)))))))" +* In the main program, call the `rep` function with the following + string argument to define a new control structure. +``` +"(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)))))))" +``` * Note that `cond` calls the `throw` function when `cond` is called with an odd number of args. The `throw` function is implemented in the next step, but it will still serve it's purpose here by causing an undefined symbol error. - * `or`: "(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))))))))" @@ -1521,27 +1521,6 @@ diff -urp ../process/step9_try.txt ../process/stepA_mal.txt entered by the user is returned as a string. If the user sends an end-of-file (usually Ctrl-D), then nil is returned. -* Add meta-data support to mal functions by adding a new metadata - attribute on mal functions that refers to another mal value/type - (nil by default). Add the following metadata related core functions: - * `meta`: this takes a single mal function argument and returns the - value of the metadata attribute. - * `with-meta`: this function takes two arguments. The first argument - is a mal function and the second argument is another mal - value/type to set as metadata. A copy of the mal function is - returned that has its `meta` attribute set to the second argument. - Note that it is important that the environment and macro attribute - of mal function are retained when it is copied. - * Add a reader-macro that expands the token "^" to - return a new list that contains the symbol "with-meta" and the - result of reading the next next form (2nd argument) (`read_form`) and the - next form (1st argument) in that order - (metadata comes first with the ^ macro and the function second). - * If you implemented as `defmacro!` to mutate an existing function - without copying it, you can now use the function copying mechanism - used for metadata to make functions immutable even in the - defmacro! case... - * Add a new "\*host-language\*" (symbol) entry to your REPL environment. The value of this entry should be a mal string containing the name of the current implementation. @@ -1552,6 +1531,7 @@ diff -urp ../process/step9_try.txt ../process/stepA_mal.txt "(println (str \"Mal [\" \*host-language\* \"]\"))". * Ensure that the REPL environment contains definitions for `time-ms`, + `meta`, `with-meta`, `fn?` `string?`, `number?`, `seq`, and `conj`. It doesn't really matter what they do at this stage: they just need to be defined. Making them functions that raise a "not implemented" exception would be @@ -1608,37 +1588,31 @@ implementation to run a mal implementation which itself runs the mal implementation. -#### Optional: gensym - -The `or` macro we introduced at step 8 has a bug. It defines a -variable called `or_FIXME`, which "shadows" such a binding from the -user's code (which uses the macro). If a user has a variable called -`or_FIXME`, it cannot be used as an `or` macro argument. In order to -fix that, we'll introduce `gensym`: a function which returns a symbol -which was never used before anywhere in the program. This is also an -example for the use of mal atoms to keep state (the state here being -the number of symbols produced by `gensym` so far). - -Previously you used `rep` to define the `or` macro. Remove that -definition and use `rep` to define the new counter, `gensym` function -and the clean `or` macro. Here are the string arguments you need to -pass to `rep`: -``` -"(def! inc (fn* [x] (+ x 1)))" - -"(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" - -"(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" -``` - -For extra information read [Peter Seibel's thorough discussion about -`gensym` and leaking macros in Common Lisp](http://www.gigamonkeys.com/book/macros-defining-your-own.html#plugging-the-leaks). - - #### Optional additions -* Add metadata support to other composite data types (lists, vectors - and hash-maps), and to native functions. +* Add meta-data support to composite data types (lists, vectors + and hash-maps), and to functions (native or not), by adding a new + metadata attribute that refers to another mal value/type + (nil by default). Add the following metadata related core functions + (and remove any stub versions): + * `meta`: this takes a single mal function argument and returns the + value of the metadata attribute. + * `with-meta`: this function takes two arguments. The first argument + is a mal function and the second argument is another mal + value/type to set as metadata. A copy of the mal function is + returned that has its `meta` attribute set to the second argument. + Note that it is important that the environment and macro attribute + of mal function are retained when it is copied. + * Add a reader-macro that expands the token "^" to + return a new list that contains the symbol "with-meta" and the + result of reading the next next form (2nd argument) (`read_form`) and the + next form (1st argument) in that order + (metadata comes first with the ^ macro and the function second). + * If you implemented as `defmacro!` to mutate an existing function + without copying it, you can now use the function copying mechanism + used for metadata to make functions immutable even in the + defmacro! case... + * Add the following new core functions (and remove any stub versions): * `time-ms`: takes no arguments and returns the number of milliseconds since epoch (00:00:00 UTC January 1, 1970), or, if diff --git a/process/step8_macros.txt b/process/step8_macros.txt index b84b73a339..93da781a57 100644 --- a/process/step8_macros.txt +++ b/process/step8_macros.txt @@ -52,7 +52,6 @@ repl_env.set('*ARGV*, cmdline_args[1..]) 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 cmdline_args: rep("(load-file \"" + args[0] + "\")"); exit 0 diff --git a/process/step9_try.txt b/process/step9_try.txt index 0c070e8de3..2641805440 100644 --- a/process/step9_try.txt +++ b/process/step9_try.txt @@ -53,7 +53,6 @@ repl_env.set('*ARGV*, cmdline_args[1..]) 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 cmdline_args: rep("(load-file \"" + args[0] + "\")"); exit 0 diff --git a/process/stepA_mal.txt b/process/stepA_mal.txt index bbb8b405c0..b88a5afa8b 100644 --- a/process/stepA_mal.txt +++ b/process/stepA_mal.txt @@ -54,9 +54,6 @@ rep("(def! *host-language* \"racket\")") 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("(def! inc (fn* [x] (+ x 1)))") -rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if cmdline_args: rep("(load-file \"" + args[0] + "\")"); exit 0 diff --git a/ps/step8_macros.ps b/ps/step8_macros.ps index 51eabc98d2..925b179631 100644 Binary files a/ps/step8_macros.ps and b/ps/step8_macros.ps differ diff --git a/ps/step9_try.ps b/ps/step9_try.ps index 207b6f6541..c25168f179 100644 Binary files a/ps/step9_try.ps and b/ps/step9_try.ps differ diff --git a/ps/stepA_mal.ps b/ps/stepA_mal.ps index 7cecd70bb9..f6032980ce 100644 Binary files a/ps/stepA_mal.ps and b/ps/stepA_mal.ps differ diff --git a/python/step8_macros.py b/python/step8_macros.py index cdf7969306..9c8d392a34 100644 --- a/python/step8_macros.py +++ b/python/step8_macros.py @@ -135,7 +135,6 @@ def REP(str): 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 len(sys.argv) >= 2: REP('(load-file "' + sys.argv[1] + '")') diff --git a/python/step9_try.py b/python/step9_try.py index a6fb42903d..b1b591bce5 100644 --- a/python/step9_try.py +++ b/python/step9_try.py @@ -157,7 +157,6 @@ def REP(str): 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 len(sys.argv) >= 2: REP('(load-file "' + sys.argv[1] + '")') diff --git a/python/stepA_mal.py b/python/stepA_mal.py index 0cada9c46e..c9bae23eda 100644 --- a/python/stepA_mal.py +++ b/python/stepA_mal.py @@ -161,9 +161,6 @@ def REP(str): 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("(def! inc (fn* [x] (+ x 1)))") -REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if len(sys.argv) >= 2: REP('(load-file "' + sys.argv[1] + '")') diff --git a/r/step8_macros.r b/r/step8_macros.r index d8d3ba192f..33d251f7fa 100644 --- a/r/step8_macros.r +++ b/r/step8_macros.r @@ -154,7 +154,6 @@ Env.set(repl_env, "*ARGV*", new.list()) . <- 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))))))))") args <- commandArgs(trailingOnly = TRUE) diff --git a/r/step9_try.r b/r/step9_try.r index 049d660542..f3c5d42128 100644 --- a/r/step9_try.r +++ b/r/step9_try.r @@ -168,7 +168,6 @@ Env.set(repl_env, "*ARGV*", new.list()) . <- 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))))))))") args <- commandArgs(trailingOnly = TRUE) diff --git a/r/stepA_mal.r b/r/stepA_mal.r index b448ff985c..2d610526b2 100644 --- a/r/stepA_mal.r +++ b/r/stepA_mal.r @@ -169,9 +169,6 @@ Env.set(repl_env, "*ARGV*", new.list()) . <- 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("(def! inc (fn* [x] (+ x 1)))") -. <- rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -. <- rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") args <- commandArgs(trailingOnly = TRUE) diff --git a/racket/step8_macros.rkt b/racket/step8_macros.rkt index ca281057d8..ebcb71e8af 100755 --- a/racket/step8_macros.rkt +++ b/racket/step8_macros.rkt @@ -126,7 +126,6 @@ (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))))))))") ) diff --git a/racket/step9_try.rkt b/racket/step9_try.rkt index 79f21b63b4..06ec758180 100755 --- a/racket/step9_try.rkt +++ b/racket/step9_try.rkt @@ -142,7 +142,6 @@ (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))))))))") ) diff --git a/racket/stepA_mal.rkt b/racket/stepA_mal.rkt index aea36db7d1..dfdfb3ad09 100755 --- a/racket/stepA_mal.rkt +++ b/racket/stepA_mal.rkt @@ -143,9 +143,6 @@ (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 "(def! inc (fn* [x] (+ x 1)))") -(rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") ) diff --git a/rexx/step8_macros.rexx b/rexx/step8_macros.rexx index 7430a0b0e7..60482a096f 100644 --- a/rexx/step8_macros.rexx +++ b/rexx/step8_macros.rexx @@ -245,7 +245,6 @@ main: x = re("(def! not (fn* (a) (if a false true)))") x = re('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))') x = re("(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)))))))"); - x = re("(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))))))))"); err = "" if command_line_args.0 > 0 then do diff --git a/rexx/step9_try.rexx b/rexx/step9_try.rexx index 86a6d6e993..d201b37acf 100644 --- a/rexx/step9_try.rexx +++ b/rexx/step9_try.rexx @@ -261,7 +261,6 @@ main: x = re("(def! not (fn* (a) (if a false true)))") x = re('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))') x = re("(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)))))))"); - x = re("(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))))))))"); err = "" if command_line_args.0 > 0 then do diff --git a/rexx/stepA_mal.rexx b/rexx/stepA_mal.rexx index 04c2da19ba..3c127a3fdb 100644 --- a/rexx/stepA_mal.rexx +++ b/rexx/stepA_mal.rexx @@ -263,9 +263,6 @@ main: x = re("(def! not (fn* (a) (if a false true)))") x = re('(def! load-file (fn* (f) (eval (read-string (str "(do " (slurp f) ")")))))') x = re("(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)))))))"); - x = re("(def! inc (fn* [x] (+ x 1)))") - x = re('(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str "G__" (swap! counter inc))))))') - x = re("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") err = "" if command_line_args.0 > 0 then do diff --git a/rpython/step8_macros.py b/rpython/step8_macros.py index c231b10d87..811cd14b0a 100644 --- a/rpython/step8_macros.py +++ b/rpython/step8_macros.py @@ -168,7 +168,6 @@ def REP(str, env): REP("(def! not (fn* (a) (if a false true)))", repl_env) REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - 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))))))))", repl_env) if len(argv) >= 2: REP('(load-file "' + argv[1] + '")', repl_env) diff --git a/rpython/step9_try.py b/rpython/step9_try.py index 16a4062277..9c58d7b2fb 100644 --- a/rpython/step9_try.py +++ b/rpython/step9_try.py @@ -186,7 +186,6 @@ def REP(str, env): REP("(def! not (fn* (a) (if a false true)))", repl_env) REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - 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))))))))", repl_env) if len(argv) >= 2: REP('(load-file "' + argv[1] + '")', repl_env) diff --git a/rpython/stepA_mal.py b/rpython/stepA_mal.py index 5fd5592bae..6c73a48cdb 100644 --- a/rpython/stepA_mal.py +++ b/rpython/stepA_mal.py @@ -196,9 +196,6 @@ def REP(str, env): REP("(def! not (fn* (a) (if a false true)))", repl_env) REP("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) 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)))))))", repl_env) - REP("(def! inc (fn* [x] (+ x 1)))", repl_env) - REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env) - REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env) if len(argv) >= 2: REP('(load-file "' + argv[1] + '")', repl_env) diff --git a/ruby/step8_macros.rb b/ruby/step8_macros.rb index e29e1e093f..46a64e5355 100644 --- a/ruby/step8_macros.rb +++ b/ruby/step8_macros.rb @@ -147,7 +147,6 @@ def PRINT(exp) RE["(def! not (fn* (a) (if a false true)))"] RE["(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"] RE["(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)))))))"] -RE["(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 ARGV.size > 0 RE["(load-file \"" + ARGV[0] + "\")"] diff --git a/ruby/step9_try.rb b/ruby/step9_try.rb index 3a00491216..96fc5ee24c 100644 --- a/ruby/step9_try.rb +++ b/ruby/step9_try.rb @@ -162,7 +162,6 @@ def PRINT(exp) RE["(def! not (fn* (a) (if a false true)))"] RE["(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"] RE["(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)))))))"] -RE["(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 ARGV.size > 0 RE["(load-file \"" + ARGV[0] + "\")"] diff --git a/ruby/stepA_mal.rb b/ruby/stepA_mal.rb index 756811a68a..14f7f785bf 100644 --- a/ruby/stepA_mal.rb +++ b/ruby/stepA_mal.rb @@ -169,9 +169,6 @@ def PRINT(exp) RE["(def! not (fn* (a) (if a false true)))"] RE["(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"] RE["(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)))))))"] -RE["(def! inc (fn* [x] (+ x 1)))"] -RE["(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"] -RE["(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"] if ARGV.size > 0 RE["(load-file \"" + ARGV[0] + "\")"] diff --git a/rust/step8_macros.rs b/rust/step8_macros.rs index 2c3bd341c8..02cb6de13d 100644 --- a/rust/step8_macros.rs +++ b/rust/step8_macros.rs @@ -303,7 +303,6 @@ fn main() { let _ = rep("(def! not (fn* (a) (if a false true)))", &repl_env); let _ = rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", &repl_env); let _ = 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)))))))", &repl_env); - let _ = 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))))))))", &repl_env); // Invoked with arguments diff --git a/rust/step9_try.rs b/rust/step9_try.rs index 3c7874ff57..1d91d762f3 100644 --- a/rust/step9_try.rs +++ b/rust/step9_try.rs @@ -324,7 +324,6 @@ fn main() { let _ = rep("(def! not (fn* (a) (if a false true)))", &repl_env); let _ = rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", &repl_env); let _ = 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)))))))", &repl_env); - let _ = 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))))))))", &repl_env); // Invoked with arguments diff --git a/rust/stepA_mal.rs b/rust/stepA_mal.rs index b65359ae69..2692fddebe 100644 --- a/rust/stepA_mal.rs +++ b/rust/stepA_mal.rs @@ -327,9 +327,6 @@ fn main() { let _ = rep("(def! not (fn* (a) (if a false true)))", &repl_env); let _ = rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", &repl_env); let _ = 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)))))))", &repl_env); - let _ = rep("(def! inc (fn* [x] (+ x 1)))", &repl_env); - let _ = rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", &repl_env); - let _ = rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", &repl_env); // Invoked with arguments diff --git a/scala/step8_macros.scala b/scala/step8_macros.scala index 48d15c252f..0620612545 100644 --- a/scala/step8_macros.scala +++ b/scala/step8_macros.scala @@ -186,7 +186,6 @@ object step8_macros { 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 (args.length > 0) { diff --git a/scala/step9_try.scala b/scala/step9_try.scala index cc997bbe62..fe6df01145 100644 --- a/scala/step9_try.scala +++ b/scala/step9_try.scala @@ -207,7 +207,6 @@ object step9_try { 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 (args.length > 0) { diff --git a/scala/stepA_mal.scala b/scala/stepA_mal.scala index 722620a517..bbdbd09848 100644 --- a/scala/stepA_mal.scala +++ b/scala/stepA_mal.scala @@ -208,9 +208,6 @@ object stepA_mal { 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("(def! inc (fn* [x] (+ x 1)))") - REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") - REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if (args.length > 0) { diff --git a/scheme/lib/core.sld b/scheme/lib/core.sld index 4d615b8d0e..44fd56335d 100644 --- a/scheme/lib/core.sld +++ b/scheme/lib/core.sld @@ -275,7 +275,7 @@ ((func? x) (let ((func (make-func (func-ast x) (func-params x) (func-env x) (func-fn x)))) - (func-macro?-set! func (func-macro? x)) + (func-macro?-set! func #f) (func-meta-set! func meta) func)) (else diff --git a/scheme/step8_macros.scm b/scheme/step8_macros.scm index c9f177e3ed..07bc86c70f 100644 --- a/scheme/step8_macros.scm +++ b/scheme/step8_macros.scm @@ -171,9 +171,7 @@ (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))))))))") (define (main) diff --git a/scheme/step9_try.scm b/scheme/step9_try.scm index b28e786ce2..a8d99cde01 100644 --- a/scheme/step9_try.scm +++ b/scheme/step9_try.scm @@ -189,9 +189,7 @@ (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))))))))") (define (main) diff --git a/scheme/stepA_mal.scm b/scheme/stepA_mal.scm index 408eed3ec9..af1f10456e 100644 --- a/scheme/stepA_mal.scm +++ b/scheme/stepA_mal.scm @@ -191,11 +191,6 @@ (rep "(def! not (fn* (a) (if a false true)))") (rep "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") - -(rep "(def! inc (fn* [x] (+ x 1)))") -(rep "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") - -(rep "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") (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)))))))") (define (main) diff --git a/skew/step8_macros.sk b/skew/step8_macros.sk index 44565979e0..3c6307b72e 100644 --- a/skew/step8_macros.sk +++ b/skew/step8_macros.sk @@ -153,7 +153,6 @@ def main { RE("(def! not (fn* (a) (if a false true)))") RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") RE("(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)))))))") - RE("(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 argv.count > 0 { RE("(load-file \"" + argv[0] + "\")") diff --git a/skew/step9_try.sk b/skew/step9_try.sk index e951631552..bb93792a1a 100644 --- a/skew/step9_try.sk +++ b/skew/step9_try.sk @@ -167,7 +167,6 @@ def main { RE("(def! not (fn* (a) (if a false true)))") RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") RE("(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)))))))") - RE("(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 argv.count > 0 { RE("(load-file \"" + argv[0] + "\")") diff --git a/skew/stepA_mal.sk b/skew/stepA_mal.sk index 798aa15671..983c3e107f 100644 --- a/skew/stepA_mal.sk +++ b/skew/stepA_mal.sk @@ -168,9 +168,6 @@ def main { RE("(def! not (fn* (a) (if a false true)))") RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") RE("(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)))))))") - RE("(def! inc (fn* [x] (+ x 1)))") - RE("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") - RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if argv.count > 0 { RE("(load-file \"" + argv[0] + "\")") diff --git a/swift/step8_macros.swift b/swift/step8_macros.swift index e0391ceda1..eb99f0fb3b 100644 --- a/swift/step8_macros.swift +++ b/swift/step8_macros.swift @@ -583,8 +583,6 @@ func main() { RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env) RE("(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)))))))", env) - RE("(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))))))))", env) env.set(kSymbolEval, make_builtin({ try! unwrap_args($0) { diff --git a/swift/step9_try.swift b/swift/step9_try.swift index b0b8b31449..40973200c9 100644 --- a/swift/step9_try.swift +++ b/swift/step9_try.swift @@ -616,8 +616,6 @@ func main() { RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env) RE("(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)))))))", env) - RE("(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))))))))", env) env.set(kSymbolEval, make_builtin({ try! unwrap_args($0) { diff --git a/swift/stepA_mal.swift b/swift/stepA_mal.swift index d1b0adf0ff..cbdaa79a51 100644 --- a/swift/stepA_mal.swift +++ b/swift/stepA_mal.swift @@ -617,10 +617,6 @@ func main() { RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env) RE("(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)))))))", env) - RE("(def! inc (fn* [x] (+ x 1)))", env) - RE("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", env) - RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) " + - "(let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", env) env.set(kSymbolEval, make_builtin({ try! unwrap_args($0) { diff --git a/swift3/Sources/step8_macros/main.swift b/swift3/Sources/step8_macros/main.swift index a53483f0f7..46c3cc3a97 100644 --- a/swift3/Sources/step8_macros/main.swift +++ b/swift3/Sources/step8_macros/main.swift @@ -217,7 +217,6 @@ try repl_env.set(MalVal.MalSymbol("*ARGV*"), list(Array(args))) try rep("(def! not (fn* (a) (if a false true)))") try rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") try 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)))))))") -try 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 CommandLine.arguments.count > 1 { diff --git a/swift3/Sources/step9_try/main.swift b/swift3/Sources/step9_try/main.swift index 900dd3e371..7344bba43d 100644 --- a/swift3/Sources/step9_try/main.swift +++ b/swift3/Sources/step9_try/main.swift @@ -250,7 +250,6 @@ try repl_env.set(MalVal.MalSymbol("*ARGV*"), list(Array(args))) try rep("(def! not (fn* (a) (if a false true)))") try rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") try 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)))))))") -try 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 CommandLine.arguments.count > 1 { diff --git a/swift3/Sources/stepA_mal/main.swift b/swift3/Sources/stepA_mal/main.swift index b7a5153256..55d81547bd 100644 --- a/swift3/Sources/stepA_mal/main.swift +++ b/swift3/Sources/stepA_mal/main.swift @@ -251,9 +251,6 @@ try rep("(def! *host-language* \"swift\")") try rep("(def! not (fn* (a) (if a false true)))") try rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))") try 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)))))))") -try rep("(def! inc (fn* [x] (+ x 1)))") -try rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))") -try rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") if CommandLine.arguments.count > 1 { diff --git a/swift4/Sources/step8_macros/main.swift b/swift4/Sources/step8_macros/main.swift index e4bc7ef9da..b9d1f48a6a 100644 --- a/swift4/Sources/step8_macros/main.swift +++ b/swift4/Sources/step8_macros/main.swift @@ -166,7 +166,6 @@ repl_env.set([], forKey: Symbol("*ARGV*")) try rep("(def! not (fn* (a) (if a false true)))", env: repl_env) try rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env: repl_env) try 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)))))))", env: repl_env) -try 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))))))))", env: repl_env) if CommandLine.argc > 1 { let fileName = CommandLine.arguments[1], diff --git a/swift4/Sources/step9_try/main.swift b/swift4/Sources/step9_try/main.swift index 26624f7205..c2bc8ec645 100644 --- a/swift4/Sources/step9_try/main.swift +++ b/swift4/Sources/step9_try/main.swift @@ -178,7 +178,6 @@ repl_env.set([], forKey: Symbol("*ARGV*")) try rep("(def! not (fn* (a) (if a false true)))", env: repl_env) try rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env: repl_env) try 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)))))))", env: repl_env) -try 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))))))))", env: repl_env) if CommandLine.argc > 1 { let fileName = CommandLine.arguments[1], diff --git a/swift4/Sources/stepA_mal/main.swift b/swift4/Sources/stepA_mal/main.swift index a2cc2b743d..a1f9eb51df 100644 --- a/swift4/Sources/stepA_mal/main.swift +++ b/swift4/Sources/stepA_mal/main.swift @@ -180,9 +180,6 @@ repl_env.set("Swift4", forKey: Symbol("*host-language*")) try rep("(def! not (fn* (a) (if a false true)))", env: repl_env) try rep("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env: repl_env) try 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)))))))", env: repl_env) -try rep("(def! inc (fn* [x] (+ x 1)))", env: repl_env) -try rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", env: repl_env) -try rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", env: repl_env) if CommandLine.argc > 1 { let fileName = CommandLine.arguments[1], diff --git a/tcl/step8_macros.tcl b/tcl/step8_macros.tcl index 7329d8b4c0..9ee25aa3d2 100644 --- a/tcl/step8_macros.tcl +++ b/tcl/step8_macros.tcl @@ -227,7 +227,6 @@ $repl_env set "*ARGV*" [list_new $argv_list] RE "(def! not (fn* (a) (if a false true)))" $repl_env RE "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" $repl_env RE "(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)))))))" $repl_env -RE "(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))))))))" $repl_env fconfigure stdout -translation binary diff --git a/tcl/step9_try.tcl b/tcl/step9_try.tcl index e190f8022f..dd4ef7882e 100644 --- a/tcl/step9_try.tcl +++ b/tcl/step9_try.tcl @@ -245,7 +245,6 @@ $repl_env set "*ARGV*" [list_new $argv_list] RE "(def! not (fn* (a) (if a false true)))" $repl_env RE "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" $repl_env RE "(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)))))))" $repl_env -RE "(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))))))))" $repl_env fconfigure stdout -translation binary diff --git a/tcl/stepA_mal.tcl b/tcl/stepA_mal.tcl index 62d4f8e163..71c09c7a2c 100644 --- a/tcl/stepA_mal.tcl +++ b/tcl/stepA_mal.tcl @@ -249,9 +249,6 @@ RE "(def! *host-language* \"tcl\")" $repl_env RE "(def! not (fn* (a) (if a false true)))" $repl_env RE "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" $repl_env RE "(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)))))))" $repl_env -RE "(def! inc (fn* \[x\] (+ x 1)))" $repl_env -RE "(def! gensym (let* \[counter (atom 0)\] (fn* \[\] (symbol (str \"G__\" (swap! counter inc))))))" $repl_env -RE "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))" $repl_env fconfigure stdout -translation binary diff --git a/tests/lib/equality.mal b/tests/lib/equality.mal index 78a0b5d453..52c42b1597 100644 --- a/tests/lib/equality.mal +++ b/tests/lib/equality.mal @@ -4,42 +4,42 @@ (load-file "../lib/equality.mal") ;=>nil -;; Testing and2 -(and2) +;; Testing bool-and +(bool-and) ;=>true -(and2 true) +(bool-and true) ;=>true -(and2 false) +(bool-and false) ;=>false -(and2 nil) +(bool-and nil) ;=>false -(and2 1) +(bool-and 1) ;=>true -(and2 1 2) +(bool-and 1 2) ;=>true -(and2 nil (nth () 1)) +(bool-and nil (nth () 1)) ;=>false -;; Testing or2 -(or2) +;; Testing bool-or +(bool-or) ;=>false -(or2 true) +(bool-or true) ;=>true -(or2 false) +(bool-or false) ;=>false -(or2 nil) +(bool-or nil) ;=>false -(or2 1) +(bool-or 1) ;=>true -(or2 1 (nth () 1)) +(bool-or 1 (nth () 1)) ;=>true -(or2 1 2) +(bool-or 1 2) ;=>true -(or2 false nil) +(bool-or false nil) ;=>false ;; Breaking equality. -(def! = (fn* [a b] (and2 (orig= a b) (cond (list? a) (list? b) (vector? a) (vector? b) true true)))) +(def! = (fn* [a b] (bool-and (orig= a b) (cond (list? a) (list? b) (vector? a) (vector? b) true true)))) (= [] ()) ;=>false diff --git a/tests/lib/test_cascade.mal b/tests/lib/test_cascade.mal index b6c2f3c106..6db6698e26 100644 --- a/tests/lib/test_cascade.mal +++ b/tests/lib/test_cascade.mal @@ -1,6 +1,24 @@ (load-file "../lib/test_cascade.mal") ;=>nil +;; Testing or +(or) +;=>nil +(or 1) +;=>1 +(or 1 2 3 4) +;=>1 +(or false 2) +;=>2 +(or false nil 3) +;=>3 +(or false nil false false nil 4) +;=>4 +(or false nil 3 false nil 4) +;=>3 +(or (or false 4)) +;=>4 + ;; Testing every? (every? first []) ;=>true diff --git a/tests/lib/trivial.mal b/tests/lib/trivial.mal index 6f2f813f49..d32ce313e1 100644 --- a/tests/lib/trivial.mal +++ b/tests/lib/trivial.mal @@ -1,6 +1,8 @@ (load-file "../lib/trivial.mal") ;=>nil +(inc 12) +;=>13 (dec 12) ;=>11 (zero? 12) @@ -9,3 +11,5 @@ ;=>true (identity 12) ;=>12 +(= (gensym) (gensym)) +;=>false diff --git a/tests/step8_macros.mal b/tests/step8_macros.mal index 598689288c..79f332abca 100644 --- a/tests/step8_macros.mal +++ b/tests/step8_macros.mal @@ -69,24 +69,6 @@ x ;=>(8 9) -;; Testing or macro -(or) -;=>nil -(or 1) -;=>1 -(or 1 2 3 4) -;=>1 -(or false 2) -;=>2 -(or false nil 3) -;=>3 -(or false nil false false nil 4) -;=>4 -(or false nil 3 false nil 4) -;=>3 -(or (or false 4)) -;=>4 - ;; Testing cond macro (cond) @@ -106,7 +88,7 @@ x ;; Testing EVAL in let* -(let* (x (or nil "yes")) x) +(let* (x (cond false "no" true "yes")) x) ;=>"yes" @@ -146,7 +128,7 @@ x ;; Testing EVAL in vector let* -(let* [x (or nil "yes")] x) +(let* [x (cond false "no" true "yes")] x) ;=>"yes" ;>>> soft=True diff --git a/tests/step9_try.mal b/tests/step9_try.mal index 1f90e31a53..5f8c606b03 100644 --- a/tests/step9_try.mal +++ b/tests/step9_try.mal @@ -177,6 +177,7 @@ (map? :abc) ;=>false + ;; ;; Testing hash-maps (hash-map "a" 1) @@ -294,11 +295,11 @@ ;=>"true \".\" false \".\" nil \".\" :keyw \".\" symb" (def! s (str {:abc "val1" :def "val2"})) -(or (= s "{:abc val1 :def val2}") (= s "{:def val2 :abc val1}")) +(cond (= s "{:abc val1 :def val2}") true (= s "{:def val2 :abc val1}") true) ;=>true (def! p (pr-str {:abc "val1" :def "val2"})) -(or (= p "{:abc \"val1\" :def \"val2\"}") (= p "{:def \"val2\" :abc \"val1\"}")) +(cond (= p "{:abc \"val1\" :def \"val2\"}") true (= p "{:def \"val2\" :abc \"val1\"}") true) ;=>true ;; @@ -377,3 +378,5 @@ (= [] {}) ;=>false +(map? cond) +;=>false diff --git a/tests/stepA_mal.mal b/tests/stepA_mal.mal index 58ba909e70..6056315b02 100644 --- a/tests/stepA_mal.mal +++ b/tests/stepA_mal.mal @@ -24,6 +24,33 @@ ;; ------- (Needed for self-hosting) ------- ;; +;; +;; Testing hash-map evaluation and atoms (i.e. an env) +(def! e (atom {"+" +})) +(swap! e assoc "-" -) +( (get @e "+") 7 8) +;=>15 +( (get @e "-") 11 8) +;=>3 +(swap! e assoc "foo" (list)) +(get @e "foo") +;=>() +(swap! e assoc "bar" '(1 2 3)) +(get @e "bar") +;=>(1 2 3) + +;; Testing for presence of optional functions +(do (list time-ms string? number? seq conj meta with-meta fn?) nil) +;=>nil + +;; ------------------------------------------------------------------ + +;>>> soft=True +;>>> optional=True +;; +;; ------- Optional Functionality -------------- +;; ------- (Not needed for self-hosting) ------- + ;; Testing metadata on functions ;; @@ -64,7 +91,6 @@ (meta +) ;=>nil - ;; ;; Make sure closures and metadata co-exist (def! gen-plusX (fn* (x) (with-meta (fn* (b) (+ x b)) {"meta" 1}))) @@ -81,33 +107,6 @@ (meta plus8) ;=>{"meta" 1} -;; -;; Testing hash-map evaluation and atoms (i.e. an env) -(def! e (atom {"+" +})) -(swap! e assoc "-" -) -( (get @e "+") 7 8) -;=>15 -( (get @e "-") 11 8) -;=>3 -(swap! e assoc "foo" (list)) -(get @e "foo") -;=>() -(swap! e assoc "bar" '(1 2 3)) -(get @e "bar") -;=>(1 2 3) - -;; Testing for presence of optional functions -(do (list time-ms string? number? seq conj) nil) -;=>nil - -;; ------------------------------------------------------------------ - -;>>> soft=True -;>>> optional=True -;; -;; ------- Optional Functionality -------------- -;; ------- (Not needed for self-hosting) ------- - ;; ;; Testing string? function (string? "") @@ -150,6 +149,8 @@ ;=>false (fn? :+) ;=>false +(fn? ^{"ismacro" true} (fn* () 0)) +;=>true ;; Testing macro? function (macro? cond) @@ -162,6 +163,8 @@ ;=>false (macro? :+) ;=>false +(macro? {}) +;=>false ;; @@ -274,18 +277,6 @@ (meta +) ;=>nil -;; -;; Testing inc -(inc 12) -;=>13 - -;; -;; Testing gensym and clean or macro -(= (gensym) (gensym)) -;=>false -(let* [or_FIXME 23] (or false (+ or_FIXME 100))) -;=>123 - ;; Loading sumdown from computations.mal (load-file "../tests/computations.mal") diff --git a/ts/step8_macros.ts b/ts/step8_macros.ts index 0c91566255..f81fa5b847 100644 --- a/ts/step8_macros.ts +++ b/ts/step8_macros.ts @@ -276,7 +276,6 @@ replEnv.set(MalSymbol.get("*ARGV*"), new MalList([])); 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" && 2 < process.argv.length) { replEnv.set(MalSymbol.get("*ARGV*"), new MalList(process.argv.slice(3).map(s => new MalString(s)))); diff --git a/ts/step9_try.ts b/ts/step9_try.ts index eb22b39bcf..2074b787b3 100644 --- a/ts/step9_try.ts +++ b/ts/step9_try.ts @@ -301,7 +301,6 @@ replEnv.set(MalSymbol.get("*ARGV*"), new MalList([])); 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" && 2 < process.argv.length) { replEnv.set(MalSymbol.get("*ARGV*"), new MalList(process.argv.slice(3).map(s => new MalString(s)))); diff --git a/ts/stepA_mal.ts b/ts/stepA_mal.ts index 61e6a15c5d..c5bbf31c91 100644 --- a/ts/stepA_mal.ts +++ b/ts/stepA_mal.ts @@ -302,9 +302,6 @@ rep(`(def! *host-language* "TypeScript")`); 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("(def! inc (fn* [x] (+ x 1)))"); -rep("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))"); -rep("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))"); if (typeof process !== "undefined" && 2 < process.argv.length) { replEnv.set(MalSymbol.get("*ARGV*"), new MalList(process.argv.slice(3).map(s => new MalString(s)))); diff --git a/vala/step8_macros.vala b/vala/step8_macros.vala index 5e909d66f0..f6cdd3652a 100644 --- a/vala/step8_macros.vala +++ b/vala/step8_macros.vala @@ -337,7 +337,6 @@ class Mal.Main : GLib.Object { setup("(def! not (fn* (a) (if a false true)))", env); setup("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env); setup("(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)))))))", env); - setup("(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))))))))", env); var ARGV = new GLib.List(); if (args.length > 1) { diff --git a/vala/step9_try.vala b/vala/step9_try.vala index 0c2fcf16db..813b27d71b 100644 --- a/vala/step9_try.vala +++ b/vala/step9_try.vala @@ -375,7 +375,6 @@ class Mal.Main : GLib.Object { setup("(def! not (fn* (a) (if a false true)))", env); setup("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env); setup("(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)))))))", env); - setup("(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))))))))", env); var ARGV = new GLib.List(); if (args.length > 1) { diff --git a/vala/stepA_mal.vala b/vala/stepA_mal.vala index d1d105f4c7..b0ed9148be 100644 --- a/vala/stepA_mal.vala +++ b/vala/stepA_mal.vala @@ -376,9 +376,6 @@ class Mal.Main : GLib.Object { setup("(def! not (fn* (a) (if a false true)))", env); setup("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", env); setup("(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)))))))", env); - setup("(def! inc (fn* [x] (+ x 1)))", env); - setup("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", env); - setup("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", env); var ARGV = new GLib.List(); if (args.length > 1) { diff --git a/vb/step8_macros.vb b/vb/step8_macros.vb index 1e977aed6b..32e102d160 100644 --- a/vb/step8_macros.vb +++ b/vb/step8_macros.vb @@ -254,7 +254,6 @@ Namespace Mal 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 args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") diff --git a/vb/step9_try.vb b/vb/step9_try.vb index 690182db64..83bd1bf7e3 100644 --- a/vb/step9_try.vb +++ b/vb/step9_try.vb @@ -277,7 +277,6 @@ Namespace Mal 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 args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") diff --git a/vb/stepA_mal.vb b/vb/stepA_mal.vb index cd7f632f89..b10b43c22f 100644 --- a/vb/stepA_mal.vb +++ b/vb/stepA_mal.vb @@ -278,9 +278,6 @@ Namespace Mal 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("(def! inc (fn* [x] (+ x 1)))") - REP("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str ""G__"" (swap! counter inc))))))") - REP("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))") If args.Length > fileIdx Then REP("(load-file """ & args(fileIdx) & """)") diff --git a/vhdl/step8_macros.vhdl b/vhdl/step8_macros.vhdl index 662b3959b1..028f854538 100644 --- a/vhdl/step8_macros.vhdl +++ b/vhdl/step8_macros.vhdl @@ -411,7 +411,6 @@ architecture test of step8_macros is RE("(def! not (fn* (a) (if a false true)))", repl_env, dummy_val, err); RE("(def! load-file (fn* (f) (eval (read-string (str " & '"' & "(do " & '"' & " (slurp f) " & '"' & ")" & '"' & ")))))", repl_env, dummy_val, err); RE("(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)))))))", repl_env, dummy_val, err); - RE("(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))))))))", repl_env, dummy_val, err); if program_file /= null then REP("(load-file " & '"' & program_file.all & '"' & ")", repl_env, result, err); diff --git a/vhdl/step9_try.vhdl b/vhdl/step9_try.vhdl index 0e4b2d95c0..ece0ceab39 100644 --- a/vhdl/step9_try.vhdl +++ b/vhdl/step9_try.vhdl @@ -469,7 +469,6 @@ architecture test of step9_try is RE("(def! not (fn* (a) (if a false true)))", repl_env, dummy_val, err); RE("(def! load-file (fn* (f) (eval (read-string (str " & '"' & "(do " & '"' & " (slurp f) " & '"' & ")" & '"' & ")))))", repl_env, dummy_val, err); RE("(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)))))))", repl_env, dummy_val, err); - RE("(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))))))))", repl_env, dummy_val, err); if program_file /= null then REP("(load-file " & '"' & program_file.all & '"' & ")", repl_env, result, err); diff --git a/vhdl/stepA_mal.vhdl b/vhdl/stepA_mal.vhdl index 4006e416a0..80812c1689 100644 --- a/vhdl/stepA_mal.vhdl +++ b/vhdl/stepA_mal.vhdl @@ -470,9 +470,6 @@ architecture test of stepA_mal is RE("(def! not (fn* (a) (if a false true)))", repl_env, dummy_val, err); RE("(def! load-file (fn* (f) (eval (read-string (str " & '"' & "(do " & '"' & " (slurp f) " & '"' & ")" & '"' & ")))))", repl_env, dummy_val, err); RE("(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)))))))", repl_env, dummy_val, err); - RE("(def! inc (fn* [x] (+ x 1)))", repl_env, dummy_val, err); - RE("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str " & '"' & "G__" & '"' & " (swap! counter inc))))))", repl_env, dummy_val, err); - RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env, dummy_val, err); if program_file /= null then REP("(load-file " & '"' & program_file.all & '"' & ")", repl_env, result, err); diff --git a/vimscript/step8_macros.vim b/vimscript/step8_macros.vim index 96e676ce17..c64268df8b 100644 --- a/vimscript/step8_macros.vim +++ b/vimscript/step8_macros.vim @@ -193,7 +193,6 @@ call repl_env.set("*ARGV*", GetArgvList()) call RE("(def! not (fn* (a) (if a false true)))", repl_env) call RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) call RE("(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)))))))", repl_env) -call RE("(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))))))))", repl_env) if !empty(argv()) call RE('(load-file "' . argv(0) . '")', repl_env) diff --git a/vimscript/step9_try.vim b/vimscript/step9_try.vim index da0ea89922..5f82643838 100644 --- a/vimscript/step9_try.vim +++ b/vimscript/step9_try.vim @@ -225,7 +225,6 @@ call repl_env.set("*ARGV*", GetArgvList()) call RE("(def! not (fn* (a) (if a false true)))", repl_env) call RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) call RE("(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)))))))", repl_env) -call RE("(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))))))))", repl_env) if !empty(argv()) try diff --git a/vimscript/stepA_mal.vim b/vimscript/stepA_mal.vim index bdc00bd2b3..063a8f710b 100644 --- a/vimscript/stepA_mal.vim +++ b/vimscript/stepA_mal.vim @@ -226,9 +226,6 @@ call RE("(def! *host-language* \"vimscript\")", repl_env) call RE("(def! not (fn* (a) (if a false true)))", repl_env) call RE("(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env) call RE("(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)))))))", repl_env) -call RE("(def! inc (fn* [x] (+ x 1)))", repl_env) -call RE("(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env) -call RE("(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env) if !empty(argv()) try diff --git a/wasm/step8_macros.wam b/wasm/step8_macros.wam index 6ecaed287b..3c5efaa1cf 100644 --- a/wasm/step8_macros.wam +++ b/wasm/step8_macros.wam @@ -493,7 +493,6 @@ ($RELEASE ($RE "(def! not (fn* (a) (if a false true)))" $repl_env)) ($RELEASE ($RE "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" $repl_env)) ($RELEASE ($RE "(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)))))))" $repl_env)) - ($RELEASE ($RE "(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))))))))" $repl_env)) ;; Command line arguments diff --git a/wasm/step9_try.wam b/wasm/step9_try.wam index b9a3084aaf..b70afb1e51 100644 --- a/wasm/step9_try.wam +++ b/wasm/step9_try.wam @@ -540,7 +540,6 @@ ($RELEASE ($RE "(def! not (fn* (a) (if a false true)))" $repl_env)) ($RELEASE ($RE "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" $repl_env)) ($RELEASE ($RE "(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)))))))" $repl_env)) - ($RELEASE ($RE "(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))))))))" $repl_env)) ;; Command line arguments diff --git a/wasm/stepA_mal.wam b/wasm/stepA_mal.wam index 5935ef916e..3caff191f6 100644 --- a/wasm/stepA_mal.wam +++ b/wasm/stepA_mal.wam @@ -541,9 +541,6 @@ ($RELEASE ($RE "(def! not (fn* (a) (if a false true)))" $repl_env)) ($RELEASE ($RE "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))" $repl_env)) ($RELEASE ($RE "(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)))))))" $repl_env)) - ($RELEASE ($RE "(def! inc (fn* [x] (+ x 1)))" $repl_env)) - ($RELEASE ($RE "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))" $repl_env)) - ($RELEASE ($RE "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (c (gensym)) `(let* (~c ~(first xs)) (if ~c ~c (or ~@(rest xs)))))))))" $repl_env)) ;; Command line arguments (local.set $res ($MAP_LOOP_START (global.get $LIST_T))) diff --git a/yorick/step8_macros.i b/yorick/step8_macros.i index c5c5fb840f..cf77d268a6 100644 --- a/yorick/step8_macros.i +++ b/yorick/step8_macros.i @@ -227,7 +227,6 @@ func main(void) RE, "(def! not (fn* (a) (if a false true)))", repl_env RE, "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env RE, "(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)))))))", repl_env - RE, "(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))))))))", repl_env if (numberof(command_line_args) > 0) { RE, "(load-file \"" + command_line_args(1) + "\")", repl_env diff --git a/yorick/step9_try.i b/yorick/step9_try.i index bb1c2123be..b0899741f4 100644 --- a/yorick/step9_try.i +++ b/yorick/step9_try.i @@ -241,7 +241,6 @@ func main(void) RE, "(def! not (fn* (a) (if a false true)))", repl_env RE, "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env RE, "(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)))))))", repl_env - RE, "(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))))))))", repl_env if (numberof(command_line_args) > 0) { RE, "(load-file \"" + command_line_args(1) + "\")", repl_env diff --git a/yorick/stepA_mal.i b/yorick/stepA_mal.i index 6b35a12964..ea5c2b32bf 100644 --- a/yorick/stepA_mal.i +++ b/yorick/stepA_mal.i @@ -242,9 +242,6 @@ func main(void) RE, "(def! not (fn* (a) (if a false true)))", repl_env RE, "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))", repl_env RE, "(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)))))))", repl_env - RE, "(def! inc (fn* [x] (+ x 1)))", repl_env - RE, "(def! gensym (let* [counter (atom 0)] (fn* [] (symbol (str \"G__\" (swap! counter inc))))))", repl_env - RE, "(defmacro! or (fn* (& xs) (if (empty? xs) nil (if (= 1 (count xs)) (first xs) (let* (condvar (gensym)) `(let* (~condvar ~(first xs)) (if ~condvar ~condvar (or ~@(rest xs)))))))))", repl_env if (numberof(command_line_args) > 0) { RE, "(load-file \"" + command_line_args(1) + "\")", repl_env