Hi all,
I'm currently working on a small project to get started with clojure.
I can't solve this problem which seem to be related to the reader.
So I ran some test against it.
-here's the clojure code:
(def text1 "testing thread")
(def T (proxy [Thread] []
(run []
(println "T
thread : (eval (println text1))")
;this works
fine so i assume the var text1 is available from
the thread
(eval (println
text1))
(println "T
thread : (eval (read-string \"(println
text1)\"))")
; this
instruction seem to be causing the problem
; Unable to
resolve symbol: text1 in this context
(eval
(read-string "(println text1)"))
)))
(println "Main thread : (eval (println text1))")
(eval (println text1))
(println "Main thread : (eval (read-string \"(println
text1)\"))")
(eval (read-string "(println text1)"))
(. T start)
-and the output:
Clojure
Main thread : (eval (println text1))
testing thread
Main thread : (eval (read-string "(println text1)"))
testing thread
1:1 user=> T thread : (eval (println text1))
testing thread
T thread : (eval (read-string "(println text1)"))
-followed by the stack trace
Exception in thread "Thread-1" java.lang.Exception: Unable to
resolve symbol: text1 in this context (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.analyze(Compiler.java:4330)
at clojure.lang.Compiler.analyze(Compiler.java:4276)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2761)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4488)
at clojure.lang.Compiler.analyze(Compiler.java:4315)
at clojure.lang.Compiler.analyze(Compiler.java:4276)
at
clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:3852)
at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3687)
at
clojure.lang.Compiler$FnMethod.access$1100(Compiler.java:3564)
at clojure.lang.Compiler$FnExpr.parse(Compiler.java:2953)
at clojure.lang.Compiler.analyzeSeq(Compiler.java:4484)
at clojure.lang.Compiler.analyze(Compiler.java:4315)
at clojure.lang.Compiler.eval(Compiler.java:4520)
at clojure.core$eval__3975.invoke(core.clj:1743)
at user$fn__88$fn__90.invoke(testReader.clj:8)
at clojure.proxy.java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Exception: Unable to resolve symbol: text1 in
this context
at clojure.lang.Compiler.resolveIn(Compiler.java:4671)
at clojure.lang.Compiler.resolve(Compiler.java:4617)
at clojure.lang.Compiler.analyzeSymbol(Compiler.java:4594)
at clojure.lang.Compiler.analyze(Compiler.java:4297)
... 15 more
So my question is would it be possible to get access to text1 in the
thread using this code (eval (read-string "(println text1)"))?
Is the reader really involved in this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
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
-~----------~----~----~----~------~----~------~--~---