I appreciate your reply.
The following is the entire code where I encountered this problem.
My intention was for debugging purpose to print the result of every nested
expression in a form.
(ns debux.lab
(:require (clojure [walk :as walk])))
;; For internal debugging
(defmacro ^:private dbg_
[form]
`(let [return# ~form]
(println ">> dbg_:" (pr-str '~form) "=>" return# "<<")
return#))
(def a 2)
(def b 3)
(def c 5)
(defn- dispatch
[node]
(cond
(list? node)
(do (eval `(dbg_ ~node))
node)
(and (symbol? node)
(not (fn? (eval `~node))))
(do (eval `(dbg_ ~node))
node)
:else node))
(defn- tree-walk
[tree]
(walk/postwalk dispatch tree))
;; dbg for nested expressions
(defmacro dbgn [form]
(tree-walk form))
;;; test samples
;; This works because every symbol is declared in global symbols
(dbgn (* c (+ a b)))
; >> dbg_: c => 5 <<
; >> dbg_: a => 2 <<
; >> dbg_: b => 3 <<
; >> dbg_: (+ a b) => 5 <<
; >> dbg_: (* c (+ a b)) => 25 <<
;; This works too, because literal syntax-quotes are used.
(let [a 10 b 20 c 30]
(eval `(* ~c (+ ~a ~b))))
; => 900
;; But this doesn't work, because literal syntax-quotes can't be used in
this case.
(let [a 10 b 20 c 30]
(dbgn (* c (+ a b))))
; 2. Unhandled clojure.lang.Compiler$CompilerException
; Error compiling work/philos/debux/src/debux/lab.clj at (52:3)
;
; 1. Caused by java.lang.UnsupportedOperationException
; Can't eval locals
;
; Compiler.java: 5943
clojure.lang.Compiler$LocalBindingExpr/eval
; Compiler.java: 6932 clojure.lang.Compiler/eval
; Compiler.java: 6890 clojure.lang.Compiler/eval
; core.clj: 3105 clojure.core/eval
; core.clj: 3101 clojure.core/eval
; ......
Any suggestion in this case?
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.