Re: Simple dosync/alter question

2009-04-06 Thread David Sletten
On Apr 6, 2009, at 9:02 AM, bgray wrote: > > I have a some what (I believe) easy question. Could someone let me > know what I'm doing wrong? A simplified version of what I'm trying to > do looks like this: > > user=> (def foo (ref 0)) > #'user/foo > user=> (defn square [x] (* x x)) > #'user/sq

Re: Simple dosync/alter question

2009-04-06 Thread David Nolen
I think what you want is: (def foo (ref 0)) (defn square [x] (* x x)) (defn square-ref [x] (dosync (ref-set foo (square x (square-ref 2) On Mon, Apr 6, 2009 at 3:02 PM, bgray wrote: > > I have a some what (I believe) easy question. Could someone let me > know what I'm doing wrong? A simpli

Re: Simple dosync/alter question

2009-04-06 Thread Paul Stadig
Alter expects a function that take the current value of the ref it will alter as the first arg. I think what you want to do is ref-set. user=> (doc alter) - clojure.core/alter ([ref fun & args]) Must be called in a transaction. Sets the in-transaction-value of ref to:

Simple dosync/alter question

2009-04-06 Thread bgray
I have a some what (I believe) easy question. Could someone let me know what I'm doing wrong? A simplified version of what I'm trying to do looks like this: user=> (def foo (ref 0)) #'user/foo user=> (defn square [x] (* x x)) #'user/square user=> (defn square-ref [x] (dosync (alter foo square x