On Tue, Nov 30, 2010 at 7:23 PM, Alex Osborne <a...@meshy.org> wrote:
>> Eww. Why (locking ...)? Why not just (swap! result #(if (= % sentinel)
>> (function) %))?
>
> From the doc string: "The function can have side effects."
>
> Sometimes a lock is the right tool for the job.

I put a println in a swap! function once and the world didn't end.

It just seems to me that the code that was posted more or less
reinvents a (weak) form of swap! using reset! and locking. The
requirements for runonce seem clear enough: the thing should run only
once, so, you should check if it has already been run and if not run
it and the check-and-maybe-run needs to be done atomically. And the
original code even uses an atom to represent the has-it-run-yet?
state. And swap!s on a single atom are supposed to be atomic, any
given swap! definitely happening before or after any other given swap!
on the same atom. So...

-- 
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 from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to