Browse files

(ins-ns) should work in :annotate

  • Loading branch information...
1 parent 86cbda9 commit f44e2366f9a4af53caa8fefe72b495bc4c12513b @skanev skanev committed Apr 18, 2013
Showing with 12 additions and 8 deletions.
  1. +7 −7 src/lectures/annotate.clj
  2. +5 −1 test/lectures/annotate_test.clj
View
14 src/lectures/annotate.clj
@@ -15,23 +15,23 @@
[code]
(let [code (-> (str "(do\n" code "\n)")
(str/replace #"\n(; \{(\d+)\})$" "$1")
- (str/replace #"(?m)^(.*)\s*; \{(\d+)\}$" "(store-result $2 $1)"))]
+ (str/replace #"(?m)^(.*)\s*; \{(\d+)\}$" "(lectures.sandbox/store-result $2 $1)"))]
(binding [*ns* (create-ns 'lectures.sandbox)]
(eval '(do
(ns lectures.sandbox)
(def placeholder-values (atom {}))
(defmacro store-result [number & body]
`(try
(let [value# (do ~@body)]
- (swap! ~'placeholder-values assoc ~number value#)
+ (swap! ~'lectures.sandbox/placeholder-values assoc ~number value#)
value#)
(catch Throwable e#
- (swap! ~'placeholder-values assoc ~number e#)
+ (swap! ~'lectures.sandbox/placeholder-values assoc ~number e#)
nil)))))
- (eval (read-string code))
- (let [result (eval '@placeholder-values)]
- (remove-ns 'lectures.sandbox)
- result))))
+ (eval (read-string code)))
+ (let [result (eval '@lectures.sandbox/placeholder-values)]
+ (remove-ns 'lectures.sandbox)
+ result)))
(defn- placeholder->str
[value]
View
6 test/lectures/annotate_test.clj
@@ -32,4 +32,8 @@
"(map inc [1 2 3])
; =>"
"(map inc [1 2 3])
- ; (2 3 4)"))
+ ; (2 3 4)"
+
+ ; Namespaces
+ "(in-ns 'foo)"
+ "(in-ns 'foo)"))

0 comments on commit f44e236

Please sign in to comment.