On Thu, 2008-10-09 at 02:30 -0700, [EMAIL PROTECTED] wrote:
> As bindings are not inherited by new threads, how can this be done
> without actually changing the expressions that are evaluated?
>
> I know that in March it was briefly discussed, but wouldn't it be
> useful to have a binding variant, that causes all threads forked off
> from within the expression to inherit the binding values?
After further investigation and experimentation with macros I finally
managed to trigger a NullpointerException:
Clojure
user=> (def x)
#'user/x
user=> (defmacro on-thread [env exp] `(doto (new Thread #(binding ~env (~exp)))
(start)))
nil
user=> (on-thread [x 12] (prn x))
Thread[Thread-0,5,main]
user=> 12
Exception in thread "Thread-0" java.lang.RuntimeException:
java.lang.NullPointerException
at clojure.lang.AFn.run(AFn.java:42)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
at user.eval__2393$fn__2396.invoke(Unknown Source)
at clojure.lang.AFn.run(AFn.java:38)
... 1 more
(defmacro no-thread [env exp] `(#(binding ~env (~exp)))) ; without thread for
better stack trace
nil
user=> (no-thread [x 12] (prn x))
12
java.lang.NullPointerException (NO_SOURCE_FILE:0)
user=> (.printStackTrace *e)
java.lang.NullPointerException (NO_SOURCE_FILE:0)
at clojure.lang.Compiler.eval(Compiler.java:4008)
at clojure.lang.Repl.main(Repl.java:85)
Caused by: java.lang.NullPointerException
at user.eval__2403$fn__2405.invoke(Unknown Source)
at user.eval__2403.invoke(Unknown Source)
at clojure.lang.Compiler.eval(Compiler.java:3997)
... 1 more
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---