Re: The snake again - Programming Clojure book

2009-07-10 Thread Rowdy Rednose
Awesome! Works great! (After fixing the typo in "SwingUtilites". that is :) --~--~-~--~~~---~--~~ 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

Re: The snake again - Programming Clojure book

2009-07-10 Thread Laurent PETIT
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/

Re: The snake again - Programming Clojure book

2009-07-10 Thread Christophe Grand
On Fri, Jul 10, 2009 at 3:44 PM, Rowdy Rednose wrote: > > On Jul 10, 10:28 pm, Stuart Halloway > wrote: > 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? eval is evil but... (let

Re: The snake again - Programming Clojure book

2009-07-10 Thread Laurent PETIT
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

Re: The snake again - Programming Clojure book

2009-07-10 Thread Michael Wood
2009/7/10 Rowdy Rednose : > > The idea is to have all existing code (that gets recompiled after my > redefinition) benefit from my changes automatically, although I fear > it's not considered good style to do this. Ah. Well, I've just tried: (in-ns 'clojure.core) (def old-dosync dosync) but it

Re: The snake again - Programming Clojure book

2009-07-10 Thread Rowdy Rednose
The idea is to have all existing code (that gets recompiled after my redefinition) benefit from my changes automatically, although I fear it's not considered good style to do this. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Go

Re: The snake again - Programming Clojure book

2009-07-10 Thread Michael Wood
2009/7/10 Michael Wood : > 2009/7/10 Rowdy Rednose : >> >> 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.SwingUtil

Re: The snake again - Programming Clojure book

2009-07-10 Thread Michael Wood
2009/7/10 Rowdy Rednose : > > 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)) >     (

Re: The snake again - Programming Clojure book

2009-07-10 Thread Rowdy Rednose
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

Re: The snake again - Programming Clojure book

2009-07-10 Thread Rowdy Rednose
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 pr

Re: The snake again - Programming Clojure book

2009-07-10 Thread Stuart Halloway
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

Re: The snake again - Programming Clojure book

2009-07-10 Thread Rowdy Rednose
On Jul 10, 10:28 pm, Stuart Halloway 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

Re: The snake again - Programming Clojure book

2009-07-10 Thread Stuart Halloway
Hi Rowdy, The snake uses refs because idiomatic Clojure code should not require binding to a thread. The snake game could be extended to be a simulation that runs on multiple threads (or perhaps even multiple machines) without having to change the basic code. Normally, you wouldn't build

The snake again - Programming Clojure book

2009-07-10 Thread Rowdy Rednose
Why does the Snake example in the book use refs when all mutation is done from the EDT? To verify that, I put a call to "assert-edt" in front of every dosync in snake.clj. assert-edt is defined like this: (defn assert-edt [] (assert (javax.swing.SwingUtilities/ isEventDispatchThread))) And it n