Thanks for the ideas =)
I'll use agents to represent state (I don't know how I forgot it,
thanks Harrison), they are a lot more concise than refs and make a lot
more sense in my context.
Only one problem:

user=> (def player (agent {:str 2 :dex 3}))
#=(var user/player)
user=> @player
{:str 2, :dex 3}
user=> (send (:str player) + 1)
java.lang.NullPointerException (NO_SOURCE_FILE:0)
...
Caused by: java.lang.NullPointerException
        at clojure.send__547.doInvoke(boot.clj:1044)
        at clojure.lang.RestFn.invoke(RestFn.java:445)
        at user.eval__2681.invoke(Unknown Source)
        at clojure.lang.Compiler.eval(Compiler.java:4106)
        ... 10 more

Ideas?

Regards.
Islon

On Nov 20, 9:24 pm, Timothy Pratley <[EMAIL PROTECTED]> wrote:
> Given that is the correct way to mutate state, why do we need so much
> explicit syntax?
> user=> (defn += [a b c] (dosync (commute a update-in [b] #(+ c %1))))
>
> user=> (+= player :str 1)
> {:str 56}
> ; are you a giant?
>
> Ok so if I did something like this:
> (+= player :int 5)
> (+= player :hpmax 10)
> in one thread, and on another thread did:
> (myset player :int 10)
> (myset player :hpmax 88)
>
> The operations might be interleaved whereas it might be desirable to
> do the 2 update actions in one transaction to prevent interleaving.
> Now this is really up to the programmer as to what is desired, however
> a group update is pretty trivial also:
> (myset player :int 10 :hpmax 88)
>
> Maybe there is the case where something more complex happens which I
> can't imagine and you would still need dosync... but it seems to me
> that the majority of occurrences could be hidden away by simple
> mutation functions, and these could be written much more generically
> than the one above.
> Is there an inherent problem with this approach?
>
> Regards,
> Tim.
--~--~---------~--~----~------------~-------~--~----~
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