On Sun, Nov 1, 2009 at 8:04 PM, CuppoJava <patrickli_2...@hotmail.com>wrote:
> > Hi, > For the purposes of a DSL that I'm writing, it would be very > convenient to have a break/return statement that early exits from a > subroutine. > > I'm not sure why you need this. The body of a function in clojure isn't a series of statements, it's an expression. do is then just an operator that evaluates it's various arguments and returns the last one- like + is an operator that evaluates it's various arguments and returns the sum of them. So at any point you can stop and return a value, because it's an expression- you don't need a special statement for that. So, for example, you might write code like: (defn example [ x y ] (do (foo x) ; This is always done (if exit-early 3 ; if we want to stop early, we return this value (do (bar y) 4)))) A similar thing happens with loop. The default is exiting immediately- rather than having a special form to exit the loop, you have a special form to continue the loop (recur). So there is no value to having a break or return- just don't recur. Brian --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---