(dotimes[x 4](println"Happy Birthday"(if(= x 2)"Dear XXX""To You"))) -> 68
chars!
Sorry I'm getting carried away now :)

On Fri, Sep 18, 2009 at 12:26 AM, David Nolen <dnolen.li...@gmail.com>wrote:

> (dorun(map #(println"Happy Birthday %s"(if(= 2 %)"Dear XXX""To You"))(range
> 4))) ; -> 80 chars
> should produce the correct output at the repl. This is probably the most
> correct one.
>
> can we get shorter? :)
>
>
> On Fri, Sep 18, 2009 at 12: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)
>>
>>
>> On Fri, Sep 18, 2009 at 12:19 AM, Krukow <karl.kru...@gmail.com> wrote:
>> >
>> >
>> >
>> > On Sep 18, 5:53 am, Wilson MacGyver <wmacgy...@gmail.com> wrote:
>> >> 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.
>> >
>> > I'd probably just do the scala version :-)
>> >
>> > (map #(printf "Happy Birthday %s\n" (if (= 2 %) "Dear XXX" "To You"))
>> > (range 4))
>> >
>> > But remember that the sequence is lazy, so type it directly into repl
>> > or wrap in doall.
>> >
>> > /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
-~----------~----~----~----~------~----~------~--~---

Reply via email to