Here is a debugged version:

(in-ns 'clojure.core)
(let [old-dosync-fn @#'dosync]
  (defmacro dosync [& body]
    (let [real-dosync-job (apply old-dosync-fn body)]
      `(do
        (assert (javax.swing.SwingUtilites/isEventDispatchThread))
        ~real-dosync-job))))

HTH,

-- 
Laurent

2009/7/10 Laurent PETIT <[email protected]>:
> I think you'll have to retrieve the old dosync corresponding function, and
> call this function to get the corresponding generated code, and insert this
> code at the correct place.
> Note also that I would better use (in-ns 'clojure.core) instead of (ns
> clojure.core) (ns is reserved for the creation of a new namespace).
> But really, I would not do that at all (tweaking clojure.core), though it's
> an interesting exercise :-)
>
> something like (not tested):
>
> (in-ns 'clojure.core)
>
> (defmacro dosync [& body]
>   (let [old-dosync-fn #'dosync
>          real-dosync-job (apply old-dosync-fn body)]
>     `(do
>         (assert (javax.swing.SwingUtilites/isEventDispatchThread))
>         ~real-dosync-job))))
>
> HTH,
>
> --
> Laurent
>
> 2009/7/10 Rowdy Rednose <[email protected]>
>>
>> Actually, it didn't work (apart from having a "not" in there, which I
>> only used for testing).
>>
>> Calling sync directly works, though:
>>
>> (ns clojure.core)
>> (defmacro dosync [& body]
>>  `(do
>>     (assert (javax.swing.SwingUtilities/isEventDispatchThread))
>>     (sync nil ~...@body)))
>>
>> But can't I somehow refer to the original dosync from my new dosync
>> macro?
>>
>> On Jul 10, 11:52 pm, Rowdy Rednose <[email protected]> wrote:
>> > 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to