aboutsummaryrefslogtreecommitdiff
path: root/clojure
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-10-09 23:48:47 -0500
committerJoel Martin <github@martintribe.org>2015-01-06 21:57:24 -0600
commit01c9731649a7ed97fad0bdeac9cb75b7323c0ad6 (patch)
treed6d00e574c489b206ddf78adc12c3d535bab7440 /clojure
parent1771ab50b87c745181e4e30f94b63e3f23d33dac (diff)
downloadmal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.tar.gz
mal-01c9731649a7ed97fad0bdeac9cb75b7323c0ad6.zip
All: swap step9,A. Fixes for bash, C, perl.
step9_interop -> stepA_interop stepA_more -> step9_try C: fix glib headers bash: behavior change of declare -A and pattern replacement. perl: squelch new 5.18 warnings related to switch/given statement. Also, include some in-progress interop related files.
Diffstat (limited to 'clojure')
-rw-r--r--clojure/Makefile2
-rw-r--r--clojure/project.clj4
-rw-r--r--clojure/src/step9_try.clj (renamed from clojure/src/step9_interop.clj)24
-rw-r--r--clojure/src/stepA_interop.clj (renamed from clojure/src/stepA_more.clj)2
-rw-r--r--clojure/tests/stepA_interop.mal (renamed from clojure/tests/step9_interop.mal)0
5 files changed, 23 insertions, 9 deletions
diff --git a/clojure/Makefile b/clojure/Makefile
index 2ddfbcc..6d227a2 100644
--- a/clojure/Makefile
+++ b/clojure/Makefile
@@ -1,5 +1,5 @@
SOURCES_BASE = src/readline.clj src/reader.clj src/printer.clj
-SOURCES_LISP = src/env.clj src/core.clj src/stepA_more.clj
+SOURCES_LISP = src/env.clj src/core.clj src/stepA_interop.clj
SOURCES = $(SOURCES_BASE) $(SOURCES_LISP)
all:
diff --git a/clojure/project.clj b/clojure/project.clj
index 4e7a15f..3d7ff2e 100644
--- a/clojure/project.clj
+++ b/clojure/project.clj
@@ -18,8 +18,8 @@
:step6 {:main step6-file}
:step7 {:main step7-quote}
:step8 {:main step8-macros}
- :step9 {:main step9-interop}
- :stepA {:main stepA-more}}
+ :step9 {:main step9-try}
+ :stepA {:main stepA-interop}}
:main stepA-more)
diff --git a/clojure/src/step9_interop.clj b/clojure/src/step9_try.clj
index c4d67e5..4990d75 100644
--- a/clojure/src/step9_interop.clj
+++ b/clojure/src/step9_try.clj
@@ -1,4 +1,4 @@
-(ns step9-interop
+(ns step9-try
(:refer-clojure :exclude [macroexpand])
(:require [clojure.repl]
[readline]
@@ -94,9 +94,20 @@
'macroexpand
(macroexpand a1 env)
- 'clj*
- (eval (reader/read-string a1))
-
+ 'try*
+ (if (= 'catch* (nth a2 0))
+ (try
+ (EVAL a1 env)
+ (catch clojure.lang.ExceptionInfo ei
+ (EVAL (nth a2 2) (env/env env
+ [(nth a2 1)]
+ [(:data (ex-data ei))])))
+ (catch Throwable t
+ (EVAL (nth a2 2) (env/env env
+ [(nth a2 1)]
+ [(.getMessage t)]))))
+ (EVAL a1 env))
+
'do
(do (eval-ast (->> ast (drop-last) (drop 1)) env)
(recur (last ast) env))
@@ -141,6 +152,7 @@
(env/env-set repl-env '*ARGV* ())
;; core.mal: defined using the language itself
+(rep "(def! *host-language* \"clojure\")")
(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)))))))")
@@ -161,4 +173,6 @@
(env/env-set repl-env '*ARGV* (rest args))
(if args
(rep (str "(load-file \"" (first args) "\")"))
- (repl-loop)))
+ (do
+ (rep "(println (str \"Mal [\" *host-language* \"]\"))")
+ (repl-loop))))
diff --git a/clojure/src/stepA_more.clj b/clojure/src/stepA_interop.clj
index fc7451f..6ed9964 100644
--- a/clojure/src/stepA_more.clj
+++ b/clojure/src/stepA_interop.clj
@@ -1,4 +1,4 @@
-(ns stepA-more
+(ns stepA-interop
(:refer-clojure :exclude [macroexpand])
(:require [clojure.repl]
[readline]
diff --git a/clojure/tests/step9_interop.mal b/clojure/tests/stepA_interop.mal
index b323222..b323222 100644
--- a/clojure/tests/step9_interop.mal
+++ b/clojure/tests/stepA_interop.mal