On Fri, Sep 18, 2009 at 2:41 AM, Wilson MacGyver <wmacgy...@gmail.com>wrote:
> > Clojure REPL will display nil for anything that causes side-effect? > I had no idea! > No. The return value of println _is_ nil. map takes a collection of values and returns a new collection of values by applying the supplied fn on each element of the collection. Thus the collection of 4 nils when using map. > > On Fri, Sep 18, 2009 at 2:24 AM, Krukow <karl.kru...@gmail.com> wrote: > > Yes, the result of the computation is (nil nil nil nil), a side-effect > > is printing: > > Happy Birthday To You > > Happy Birthday To You > > Happy Birthday Dear XXX > > Happy Birthday To You. > > > > I thought you wanted to print since the Scala and Java programs > > print. > > > > If you want to compute, you could use > > > > (map #(str "Happy Birthday " (if (= 2 %) "Dear XXX" "To You")) (range > > 4)) > > > > If you want to print, and avoid a list of nils, you could use > > > > (dotimes [i 4] (printf "Happy Birthday %s\n" (if (= 2 i) "Dear XXX" > > "To You"))) > > > > which is essentially the Java version. > > > > Incidentally, > > user> (count "(dotimes [i 4] (printf \"Happy Birthday %s\n\" (if (= 2 > > i) \"Dear XXX\" \"To You\")))") > > 78 > > > > /Karl > > /Karl > > > > > > > > > -- > Omnem crede diem tibi diluxisse supremum. > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---