I'm trying to redirect the input i receive from a BufferedInputStream to the repl. I'm trying something like this:
(defmacro with-thread [nm & body] `(let [thread# (Thread. (fn [] (do ~...@body)))] (if ~nm (.setName thread# ~nm)) (.start thread#) thread#)) (defn redirect-stream [nm stream function] (with-thread nm (loop [the-char nil] (if (and the-char (not (= the-char -1))) (jprint (char the- char))) (let [value (function stream the-char)] (if (not value) (recur (.read stream) (and (> (.available stream) 0) (.read stream)) )))))) However, this raises the CPU to about 50 percent. This is due to the infinite recursion, I'm assuming? So, if i get rid of the (> available stream 0) everything runs fine except for one thing: i can't kill the thread when i want to. Instead, i have to wait until it actually reads a char from the stream before my function can check to see if i want to close the thread. If i attempt to go (.stop threadObject) it simply doesn't stop the thread returned by read-stream. How should i go about this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---