On Sun, Oct 18, 2009 at 5:59 PM, Gorsal <s...@tewebs.com> wrote: > > I'm attempting to use the function future to start something in > another thread. However, in the netbeans enclojure plugin, when i type > it into the repl, it becomes non-responsive. Is this just a bug in the > enclojure plugin or would this be normal? > > (future > (let [input-stream (:input-stream *lisp*)] > (loop [the-char (.read input-stream)] > (if (not (= the-char -1)) (jprint (char the-char))) > (recur (.read input-stream))))) >
We'd need to know more about the vars specific to your project named here, notably *lisp* and jprint. The latter is called as a function or macro and the former holds an input stream. If it redirects standard input, in particular, that will redirect it away from the REPL. Most likely, though, it's an unfortunate effect of how futures print themselves: user=> (future (* 3 4)) #<object$future$ide...@1dacb2b: 12> As you can see, futures get their values to print themselves. So executing any (future ...) expression at the REPL causes the REPL to block until the future spits out a result. If that input stream is not generating an EOF for a while, the REPL isn't responding again for a while. It's hard to use a future unless you keep a reference to it, so I suggest evaluating (def foo (future ...)) at the REPL: user=> (future (do (Thread/sleep 1000) (println "boo!") (* 3 4))) boo! #<object$future$ide...@62ad0d: 12> There should be a second's delay before the boo! and the rest of the output appears. (Enclojure users will find the "boo!" in the *out* pane rather than the Repl pane after executing this.) user=> (def calc-twelve (future (Thread/sleep 1000) (do (println "boo!") (* 3 4)))) #'user/calc-twelve user=> boo! This time, the #'user/calc-twelve and the next user=> prompt should appear instantly, and after a second's delay, the boo! should appear. (Again, enclojure users will find the boo! in a different pane. They can make the delay bigger, say changing 1000 to 10000, see the next prompt appear, switch to the *out* pane, and watch the boo! appear after a few more seconds.) --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---