This did the trick:
(ns clojure.core)
(defmacro dosync [& body]
`(do
(assert (not (javax.swing.SwingUtilities/isEventDispatchThread)))
(#'dosync ~...@body)))
This is great for testing!
Thanks for your help, Stu. And btw the book is really great so far
(and I'm almost through)! It provides a good overview of all the
different aspects of clojure. And it contains a really gentle
introduction to macros for newbies like myself.
On Jul 10, 10:55 pm, Stuart Halloway <[email protected]>
wrote:
> To rebind a macro in clojure.core you would need to first enter that
> namespace:
>
> (in-ns 'clojure.core)
>
> Or, create your own dosync in a different namespace which explicitly
> does not refer to clojure.core/dosync. See the docstring for
> clojure.core/ns for using :exclude.
>
> Stuart
>
>
>
> > On Jul 10, 10:28 pm, Stuart Halloway <[email protected]>
> > wrote:
> >> binding to a thread. The snake game could be extended to be a
> >> simulation that runs on multiple threads (or perhaps even multiple
>
> > Makes sense. For the example in the book it just seemed completely
> > redundant. And when writing Swing code, at least in Java you often
> > make use of the fact that everything is single-threaded, including all
> > events. Otherwise life would be hell.
>
> > In Clojure of course multi-threading is much easier, but I wonder
> > whether in most clojure Swing applications, I should use clojure's
> > transactions when only working on a single thread. Transactions do
> > involve some overhead, which is unnecessary in most (of my) Swing
> > applications. For cases where I have to leave the EDT, like blocking
> > io, I do take care of threading issues.
>
> >> You can rebind macros, but in order to use them you have to compile
> >> some code again.
>
> > Recompiling would be fine in this case, but how can I rebind macros?
> > When doing a
>
> > (defmacro dosync [& body] ...)
>
> > it gives me this:
>
> > java.lang.Exception: Name conflict, can't def dosync because
> > namespace: user refers to:#'clojure.core/dosync (NO_SOURCE_FILE:8)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
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
-~----------~----~----~----~------~----~------~--~---