On Oct 26, 10:37 am, Krukow <[EMAIL PROTECTED]> wrote:
> On Oct 26, 1:48 pm, "Matti Jagula" <[EMAIL PROTECTED]> wrote:
>
> > On Sat, Oct 25, 2008 at 3:19 PM, Krukow <[EMAIL PROTECTED]> wrote:
> > > I am kind of embarrassed to ask this, but is there a "correct way" to
> > > do this . Do you simply re-def a function, e.g., to time execution:
>
> > def-s are not transactional, so you have to be careful yourself. Also,
> > from what I understood, the new def is used only when the function is
> > called next time, so if you have functions with infinite or
> > long-running loops then you basically cannot re-def them. Or rather
> > you can, but it won't be used.
>
> Thanks for you reply.  Now, I am still confused but at a higher
> level ;-)
>
> Rich, any chance you can give your thoughts about this? Are there best-
> practices for thread-safe updating of running programs without down
> time?

A var's root has volatile (overwrite, last one in wins) semantics.
That means that anyone can change it and everyone will see the
changes. You *can* re-def a fn being used by a long running loop:

(defn foo []
  (let [ms 1000]
    (println "Sleeping:" ms "msecs")
    (Thread/sleep ms)))

(send-off (agent nil) (fn [_] (dotimes x 20 (foo))))

Try changing ms in foo and redef-ing it while the agent is running.

Rich
--~--~---------~--~----~------------~-------~--~----~
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
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