Re: do-asynch-periodically

2009-06-12 Thread Wrexsoul
On Jun 12, 4:58 pm, Chouser wrote: > > So it looks like when the compiler expands defonce, it actually > > evaluates a def right then and there, rather than the def only being > > evaluated when the expansion of the defonce macro is evaluated. > > Yes, the var is interned in the namespace at comp

Re: do-asynch-periodically

2009-06-12 Thread Chouser
On Fri, Jun 12, 2009 at 4:10 PM, Wrexsoul wrote: > > Eh. That works. I tried (import java.io.File) and (import java.io/ > File), as well as (import (java.io File)), mimicking the syntax > of :import in ns. > > That's another of the problems -- some things, like import, are very > tersely documente

Re: do-asynch-periodically

2009-06-12 Thread Wrexsoul
ase conditional behavior OTHER than defining the global might be desired. > A couple other comments on your code: > > > (defmacro thread [& body] > >  `(Thread. (proxy [Runnable] [] (run [] ~...@body > > Clojure functions already implement Runnable, so can be > written: &

Re: do-asynch-periodically

2009-06-12 Thread Chouser
avoids .hasRoot and doesn't need the thread macro: (defmacro defdaemon [nm & body] `(do (defonce ~nm nil) (when ~nm (.interrupt ~nm)) (def ~nm (doto (Thread. (fn [] ~...@body)) (.setDaemon true) (.start) > (defmacro do-asynch-periodical

do-asynch-periodically

2009-06-11 Thread Wrexsoul
Consider this public domain for copyright purposes. Try it at the repl with: (defn make-counter [] (let [i (atom 0)] #(do (swap! i + 1) @i))) (def *counter* (make-counter)) (do-asynch-periodically *xxx* 1 (println (*counter*))) (do-asynch-periodically *xxx* 1 (println (str "changed! "