Language Clojure
(No cheating in this version.)
| Date: | 03/06/09 |
| Author: | William James |
| URL: | n/a |
| Comments: | 4 |
| Info: | http://clojure.org |
| Score: |
(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
| Version | Author | Date | Comments | Rate |
|---|---|---|---|---|
| More clojurisk and human readable versio | Thomas G. Kristensen | 03/08/10 | 0 | |
| JVM-based functional language | Ravi Chugh / Zach Tatlock | 06/08/08 | 5 |
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!
Comments