Voting

Category

real language

Bookmarking

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

Support Us

Language clojure

(More clojurisk and human readable versio)

Date:03/08/10
Author:Thomas G. Kristensen
URL:http://g2k.dk
Comments:0
Info:http://clojure.org
Score: (4.22 in 226 votes)
(defn bottles-str [n]
  (str
    (cond
      (= 0 n) "no more bottles"
      (= 1 n) "1 bottle"
      :else (format "%d bottles" n))
    " of beer"))

(defn print-bottle [n] 
  (println (format "%s on the wall, %s." (bottles-str n) (bottles-str n)))
  (println "Take one down and pass it around," (bottles-str (dec n)) "on the wall."))
  
(defn sing [n]
  (dorun (map print-bottle (reverse (range 1 (inc n)))))
  (println "No more bottles of beer on the wall, no more bottles of beer.")
  (println "Go to the store and buy some more," (bottles-str n) "on the wall."))
  
(sing 99)

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
No cheating in this version.William James03/06/094
JVM-based functional languageRavi Chugh / Zach Tatlock06/08/085

Comments

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: