> Hey, > Having this function: > > (defn printall [s] > (if (not (empty? s)) > (do > (println (str "Item: " (first s))) > (recur (rest s))))) > > Why do is used here? what happens if I drop it? > Thanks for help and time.
In Clojure and most other Lisps, `if' has the following structure - (if test then else) If you want to have multiple forms in the `then' or `else' clause, you have to group them together, else it will become a part of the `then' clause (or will throw an error since if can take only three args). This also tells you that you are performing a side-effect since (do foo bar) will return the return value of bar and that of foo will be completely discarded. Coming back to your example, if you drop the do, then only the println part will be the `then' clause and the recur part will become the 'else' clause and will get executed only when the test is false. This will make the function print the first item and exit. I hope that was clear enough. Regards, BG -- Baishampayan Ghose b.ghose at gmail.com -- 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