This blog post got me thinking.
http://www.artima.com/weblogs/viewpost.jsp?thread=268561

Basically it contains both a Java one liner and Scala one liner.

Java:
for(int i=0; i<4; i++) { System.out.println("Happy Birthday " + (i==2
? "Dear XXX" : "To You")); }

Scala:
(1 to 4).map { i => "Happy Birthday %s".format(if (i == 3) "Dear XXX"
else "To You") }.foreach { println(_) }

the goal is to generate

Happy Birthday To You
Happy Birthday To You
Happy Birthday Dear XXX
Happy Birthday To You


I started thinking about how to do this in clojure. My first reaction was to
think of the sentences as two sequences. Uses replicate to generate
them, and map str to join them from two collections.

ie, (map str (replicate 4 "Happy Birthday ")...

Is there a more "clojure" way to do it?
because using replicate to generate the 2nd sequence seem like cheating.
ie, replicate 2 "To You", 1 "Dear XXX", and then "To You" again.



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

Reply via email to