2010/8/5 michele <michelemen...@gmail.com> > > ORIGINAL > > (defn update-positions [snake apple] > (dosync > (if (eats? @snake @apple) > (do (ref-set apple (create-apple)) > (alter snake move :grow)) > (alter snake move))) > nil) > > > WITHOUT do > > (defn update-positions [snake apple] > (dosync > (if (eats? @snake @apple) > ((ref-set apple (create-apple)) <------ Removed "do" from > here > (alter snake move :grow)) > (alter snake move))) > nil) > > > Both versions work, so why does the "do" on line 4 contribute? > > I'm not sure you're asking the right question. The right question should be (IMO) "why did the do disappear in second version. My guess is that second version is working "by chance" : the return value of (ref-set) may be a map, which is callable, thus gets called for the return value of the alter call as the key.
the first version with the do is the right one. The do wraps the 2 sides effect ref-set and alter function calls as the "succesful test branch" of the if -- 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