Re: a macro question, this time completely specified :-)

2008-11-09 Thread Stuart Halloway
Hi Rich, Wow, that's a comprehensive answer. Thanks. I am using runonce to create lancet, a build system that ties into Java's Ant. Build steps definitely do have side effects, so I will probably end up using the agent approach. Targets don't have (or ignore) return values, so I could igno

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Rich Hickey
On Nov 9, 8:21 am, Stuart Halloway <[EMAIL PROTECTED]> wrote: > You should be able to do this without the ref. Have the agent's state > contain a pair of [has-run, fn-result]. The semantics of your runonce aren't clear to me, but here are some strategies: As Chouser proposed, if you only want a

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Stuart Halloway
You should be able to do this without the ref. Have the agent's state contain a pair of [has-run, fn-result]. Stuart > Hi, > > Am 09.11.2008 um 12:23 schrieb Stuart Halloway: >> Just to make things even more fun: *None* of the proposed fixes to >> the >> concurrency bug in the original actua

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Meikel Brandmeyer
Hi, Am 09.11.2008 um 12:23 schrieb Stuart Halloway: Just to make things even more fun: *None* of the proposed fixes to the concurrency bug in the original actually preserve the` semantics of the original. All have moved from "run (usually) once, mark as done" to "mark as done, try once". This al

Re: a macro question, this time completely specified :-)

2008-11-09 Thread Stuart Halloway
One way to think about the difference between alter and commute: With a commutative function, they both get to the same end result, but commute allows more concurrency, while guaranteeing less about the return value. In particular, with commute you might not be able to see every step by lo

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Stephen C. Gilardi
On Nov 8, 2008, at 10:23 PM, Stuart Halloway wrote: > > How about: > > (defn runonce > "Create a function that will only run its argument once." > [function] > (let [call-count (ref 0)] > (fn [& args] > (when (= 1 (dosync (alter call-count inc))) > (apply function args)))

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Chouser
On Sat, Nov 8, 2008 at 10:23 PM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > How about: > > (defn runonce > "Create a function that will only run its argument once." > [function] > (let [call-count (ref 0)] > (fn [& args] > (when (= 1 (dosync (alter call-count inc))) > (

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Stuart Halloway
How about: (defn runonce "Create a function that will only run its argument once." [function] (let [call-count (ref 0)] (fn [& args] (when (= 1 (dosync (alter call-count inc))) (apply function args) > On Nov 8, 2008, at 8:31 PM, Stuart Halloway wrote: > >> >> T

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Stephen C. Gilardi
On Nov 8, 2008, at 8:31 PM, Stuart Halloway wrote: > > The defrunonce macro below works, creating a function that runs only > once and tracking its run status in metadata. > > Now, how do I write it without using eval? > > (defn runonce > "Create a function that will only run once, given a fun

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Stuart Halloway
Excellent, thanks! Stuart On Sat, Nov 8, 2008 at 8:31 PM, Stuart Halloway > > <[EMAIL PROTECTED]> wrote: >> >> (defmacro defrunonce [sym doc & forms] >> "Defines a function with runonce semantics. Curren run status >> is kept in a reference under the :has-run metadata key." >> (let [[function

Re: a macro question, this time completely specified :-)

2008-11-08 Thread Chouser
On Sat, Nov 8, 2008 at 8:31 PM, Stuart Halloway <[EMAIL PROTECTED]> wrote: > > (defmacro defrunonce [sym doc & forms] > "Defines a function with runonce semantics. Curren run status > is kept in a reference under the :has-run metadata key." > (let [[function has-run] (runonce (eval (concat (

a macro question, this time completely specified :-)

2008-11-08 Thread Stuart Halloway
The defrunonce macro below works, creating a function that runs only once and tracking its run status in metadata. Now, how do I write it without using eval? (defn runonce "Create a function that will only run once, given a function. Returns a vector containing the function and the refer