Language Clojure
(No cheating in this version.)
Date: | 03/06/09 |
Author: | William James |
URL: | n/a |
Comments: | 4 |
Info: | http://clojure.org |
Score: | (3.01 in 325 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
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
Shamit Kumar Tomar said on 12/27/09 06:57:05
Nice and small code. Like it.
Peter said on 01/30/10 23:11:37
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.
Rayne said on 03/30/10 07:52:26
printf uses Java's format under the hood. So what? "Where Java isn't broke, Clojure doesn't fix it." is a huge Clojure philosophy. This is perfectly 'Clojury'.
Rayne said on 03/30/10 07:53:31
Except for putting the closing parens on a separate line. That's just stupid.