In addition to that, prnTime should have no parens:
#(on-thread prnTime)

As it was, prnTime was running before going into on-thread, which was
acting on a runnable that's nil (the return value of prn). The
difference between the two can be seen in the output. When prnTime
runs inside the threads, its output gets mixed up with thre repl, as
you'd expect.

user=> (r4t #(on-thread prnTime))
1281109289923
nil
1281109289939
1281109289939
user=> 1281109289939

(r4t #(on-thread (prnTime)))
1281109301705
1281109301705
1281109301705
1281109301705
nil

On Aug 6, 5:34 am, Nikita Beloglazov <nikelandj...@gmail.com> wrote:
> Hi, foop
> Your error in this line:
> (r4t (on-thread (prnTime)))
> You pass to function r4t thread instead of functions. Because
> (on-thread (prnTime)) returns thread
> You must pass #(on-thread (prnTime)) instead
>
> Regards,
> Nikita Beloglazov
>
>
>
> On Fri, Aug 6, 2010 at 3:13 PM, foop1 <bsmd...@gmail.com> wrote:
> > Hi,
>
> > Iam trying to run a function in a thread assuming that threads are
> > runnable, below is my program i want to print 4 time the current date
>
> > (defn- on-thread [f]
> >          (doto (Thread. #^Runnable f)
> >            (.start)))
>
> > (defn prnTime [] (prn (System/currentTimeMillis)))
>
> > (defn r4t [f]
> >  (dotimes [n 4] (f)))
>
> > (r4t (on-thread (prnTime)))
> > iam getting this error what is wrong with this ?
> > java.lang.Thread cannot be cast to clojure.lang.IFn
>
> > Pls let me know what is wrong and how to make it run in 4 threads so
> > that i can see 4 time the system print to the screen
>
> > --
> > 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<clojure%2bunsubscr...@googlegroups.com­>
> > For more options, visit this group at
> >http://groups.google.com/group/clojure?hl=en- Hide quoted text -
>
> - Show quoted text -

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