On Sep 18, 6:24 am, Wilson MacGyver <wmacgy...@gmail.com> wrote:
> Hmmm, your solution produces nils in REPL.
>
> user=> (map #(printf "Happy Birthday %s\n" (if (= 2 %) "Dear XXX" "To
> You")) (range 4))
> (Happy Birthday To You
> Happy Birthday To You
> nil Happy Birthday Dear XXX
> nil Happy Birthday To You
> nil nil)

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
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to