2010/5/10 Anders Rune Jensen <anders.rune.jen...@gmail.com> > [...] But I was a little surprised to find out that by > default, if you don't return anything, it will set the value of the > agent to nil. [...] >
Firstly, all clojure functions always return something. Some forms, such as 'cond' and 'when', return nil as a default value. So yes, the new state of the agent will be nil, since nil is the there-is-no-value value. This is my understanding of agents: Agents, like their cousins var, atom and ref, is a way of handling state change. The 'send' and 'send-off' functions are very much like the 'swap!' of atoms and 'alter' of refs in that they take a *state transition function, that when given the current state yields the next state*. Only in this case, the state transition happens asynchronously in another thread. The points is that agents are a mechanism for managing state change. When using agents simply for the purpose of executing code in another thread, one could also use 'future'. Even though the name suggests that one has the option to fetch the result of the future expression later on, one doesn't have to. 'future' is equally fitted for run-in-another-thread-and-forget usage. // raek -- 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