Skip to content

Commit b29857c

Browse files
committed
initial implementation of with-try macro
1 parent 620dae0 commit b29857c

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

src/nodely/data.clj

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,26 +182,42 @@
182182
[env handler]
183183
(update-vals env #(catch-node % handler {:apply-to-condition? true})))
184184

185-
(defn with-try-clause-expr
186-
[[_ t s expr]]
187-
(fn [error]
188-
(when (instance? error type)
189-
expr)))
185+
#_(defn with-try-clause-expr
186+
[[_ t s expr]]
187+
(fn [error]
188+
(when (instance? error type)
189+
expr)))
190190

191191
;; '(with-try env (catch type symbol expr))
192192
;; (update-vals env (fn [error] (if (instance? error type)
193193
;; ()
194194
;; ))
195+
#_(defn with-try-expr
196+
[env & clauses]
197+
(let [clauses (for [[catch t s expr] clauses]
198+
(do (assert (= catch 'catch))
199+
[t s expr]))]))
200+
195201
(defn with-try-expr
196-
[env & clauses]
197-
(let [clauses (for [[catch t s expr] clauses]
198-
(do (assert (= catch 'catch))
199-
[t s expr]))]))
202+
[clauses]
203+
(let [clauses (into {} (for [[c t s expr] clauses]
204+
(do (assert (= c 'catch))
205+
[(resolve t) (eval `(fn [~s] ~expr))]
206+
#_[t s expr])))]
207+
clauses))
200208

201209
(defmacro with-try
202210
[env & body]
203-
`(try ~env
204-
~@body))
211+
`(with-error-handler
212+
~env
213+
~(with-try-expr body)))
214+
215+
(comment
216+
(macroexpand-1 '(with-try {:a "hi"}
217+
(catch Exception e (println e))
218+
(catch Throwable t (println t))))
219+
;
220+
)
205221

206222
(s/defn get-value :- s/Any
207223
[env :- Env

0 commit comments

Comments
 (0)