Voting

Category

real language

Bookmarking

Del.icio.us Digg Diigo DZone Earthlink Google Kick.ie
Windows Live LookLater Ma.gnolia Reddit Rojo StumbleUpon Technorati

Language Clojure

(No cheating in this version.)

Date:03/06/09
Author:William James
URL:n/a
Comments:2
Info:http://clojure.org
Score: (4.12 in 41 votes)
(defn bottles [n & [capitalize]]
  (str (if (> n 0) n (if capitalize "No more" "no more"))
    " bottle" (if (= 1 n) "" "s") " of beer" ))

(defn bot-wall [n & cap] (str (bottles n cap) " on the wall"))

(defn sing
  ;  Default is 99 times.
  ([]  (sing 99))
  ([stock]
    (doseq [i (range stock -1 -1)]
      (printf "%s, %s.\n%s.\n\n"
        (bot-wall i true) (bottles i)
        (apply str
          (if (> i 0)
            ["Take one down and pass it around, " (bot-wall (dec i))]
            ["Go to the store and buy some more, " (bot-wall stock)]
          ))))))

(sing)

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
JVM-based functional languageRavi Chugh / Zach Tatlock06/08/084

Comments

>>  Shamit Kumar Tomar said on 12/27/09 06:57:05

Shamit Kumar Tomar Nice and small code. Like it.

>>  Peter said on 01/30/10 23:11:37

Peter Isn't printf an invocation of Java? It doesn't look "clojury" to me. Java has proprietary formatting mechanism, but it also includes the printf method for its concise syntax.

Download Source | Write Comment

Add Comment

Please provide a value for the fields Name, Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.

Please don't post large portions of code here! Use the form to submit new examples or updates instead!

Name:

eMail:

URL:

Security Code:
  
Comment: