On Tue, Jan 6, 2009 at 3:01 PM, Stuart Halloway <[email protected]> wrote: > > Which is better? > > (defn reset-game [snake apple] > (dosync (ref-set apple (create-apple)) > (ref-set snake (create-snake)))) > > --or-- > > (defn reset-game [snake apple] > (dosync (ref-set apple (create-apple)) > (ref-set snake (create-snake))) > nil) > > I prefer the latter after 15 minutes thought, but am willing to be > shouted down.
The doc string for dosync doesn't say what it returns, but it seems to return the value of the last expression ... the new snake in this case. I assume the whole purpose of the second version is to make sure it returns nothing. I'm tempted to say that if a function doesn't have a name that implies what it returns or a comment describing what it returns, then callers shouldn't use it. For the sake of brevity, I have a slight preference for the first version. After all, what harm could the caller do with the return value? In this case they passed in the original snake. There doesn't seem to be any harm in the caller seeing the new one through the return value. -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] 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 -~----------~----~----~----~------~----~------~--~---
