I should add, that a new thread runs in the default environment again.

You may set the *out* variable in your thread with "binding":

(let [dummy *out*] ; to have a name for the current *out*
    (.start (Thread. (fn [] (binding [*out* dummy] (prn x))))))


Regards, alux

On 18 Mai, 09:26, alux <alu...@googlemail.com> wrote:
> Hi Preecha,
>
> output in Clojure is sent to *out* (a variable that refers to
> System.out by default). If you use emacs / slime this variable will be
> set differently. You should find your threads output in the swank-
> REPL, if you can find it somewhere.
>
> Regards, alux
>
> On 18 Mai, 03:26, Preecha P <yum...@gmail.com> wrote:
>
>
>
> > I tried to play around with thread with these lines of code. It should
> > print the value of variable but it doesn't..
>
> > In emacs.
> > user> (def x 5)
> > #'user/x
> > user> x
> > 5
> > user> (import [java.lang Thread])
> > java.lang.Thread
> > user> (.start (Thread. (fn [] (print x))))
> > nil
>
> > or with agent
> > user> (def foo (agent 0))
> > #'user/foo
> > user> foo
> > #<ag...@6af2f0d0: 0>
> > user> (send foo (fn[num] (do (println num) (inc num))))
> > #<ag...@6af2f0d0: 0>
>
> > I ran the exact same code in command-line and the thread could print
> > the output fine.
>
> > Clojure 1.1.0-master-SNAPSHOT
> > user=> (def foo (agent 0))
> > #'user/foo
> > user=> foo
> > #<ag...@194835fb: 0>
> > user=> (send foo (fn[num] (do (println num) (inc num) )))
> > 0
> > #<ag...@194835fb: 0>
>
> > I installed everything from elpa, so I guess some of the component
> > might gone wrong. Any idea ?
>
> > thanks.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Clojure" group.
> > To post to this group, send email to clojure@googlegroups.com
> > Note that posts from new members are moderated - please be patient with 
> > your first post.
> > To unsubscribe from this group, send email to
> > clojure+unsubscr...@googlegroups.com
> > For more options, visit this group 
> > athttp://groups.google.com/group/clojure?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with your 
> first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group 
> athttp://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to