Raek, thanks for taking the time to write this detailed explanation.
The alter-var-root works like a charm and I think I understand how
bound-fn would behave here.

For the case where you are using an existing java class that spawns a
thread, it seems to me that only alter-var-root would work since there
wouldn't be a way to use bound-fn at thread creation.  Am I
overlooking something?

hhh

On Nov 21, 7:05 am, Rasmus Svensson <r...@lysator.liu.se> wrote:
> 2010/11/21 HiHeelHottie <hiheelhot...@gmail.com>:
>
>
>
> > Does anybody know how to redirect the output into the repl?
>
> Thread local bindings are not passed on to new threads. Since you
> might have multiple connections to the swank server, there might me
> multiple repls, each one with their own *out*. Most often though, you
> only have one connection and in that case one option is to set the
> root binding for *out* (which is the default value to use, if it
> hasn't been overridden in the thread) to the stream connected to the
> emacs buffer:
>
>     (alter-var-root #'*out* (constantly *out*))
>
> You should evaluate this in the repl where you want the output.
>
> Another more general approach is to let the body of the new thread
> inherit the bindings of the parent thread. This is done by bound-fn,
> which has the same syntax as fn. The result of that call will be a fn,
> whose body is evaluated with the same thread local bindings as the
> parent thread. The thread where the bound-fn call is evaluated in is
> the one from which bound-fn remembers its bindings.
>
> In your case, the code would look like this (I took the liberty of
> rearranging it a bit):
>
>     (def my-thread
>       (doto (Thread. (bound-fn [] (println "inside thread")))
>         .start))
>
> Regarding the *inferior lisp* buffer: It is where the "master" repl
> will be if you start the Clojure process from within Emacs. If you
> start it with lein/cake swank (which seems to be the preferred
> approach nowadays), the terminal where you ran that command will play
> the same role (as you already noticed).
>
> I hope this answers your question...
>
> // raek

-- 
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