fork download
  1. (defn bottles [n & [capitalize]]
  2. (str (if (> n 0) n (if capitalize "No more" "no more"))
  3. " bottle" (if (= 1 n) "" "s") " of beer" ))
  4.  
  5. (defn bot-wall [n & cap] (str (bottles n cap) " on the wall"))
  6.  
  7. (defn sing
  8. ; Default is 10 times.
  9. ([] (sing 10))
  10. ([stock]
  11. (doseq [i (range stock -1 -1)]
  12. (printf "%s, %s.\n%s.\n\n"
  13. (bot-wall i true) (bottles i)
  14. (apply str
  15. (if (> i 0)
  16. ["Take one down and pass it around, " (bot-wall (dec i))]
  17. ["Go to the store and buy some more, " (bot-wall stock)]
  18. ))))))
  19.  
  20. (sing)
Success #stdin #stdout 0.91s 214656KB
stdin
Standard input is empty
stdout
10 bottles of beer on the wall, 10 bottles of beer.
Take one down and pass it around, 9 bottles of beer on the wall.

9 bottles of beer on the wall, 9 bottles of beer.
Take one down and pass it around, 8 bottles of beer on the wall.

8 bottles of beer on the wall, 8 bottles of beer.
Take one down and pass it around, 7 bottles of beer on the wall.

7 bottles of beer on the wall, 7 bottles of beer.
Take one down and pass it around, 6 bottles of beer on the wall.

6 bottles of beer on the wall, 6 bottles of beer.
Take one down and pass it around, 5 bottles of beer on the wall.

5 bottles of beer on the wall, 5 bottles of beer.
Take one down and pass it around, 4 bottles of beer on the wall.

4 bottles of beer on the wall, 4 bottles of beer.
Take one down and pass it around, 3 bottles of beer on the wall.

3 bottles of beer on the wall, 3 bottles of beer.
Take one down and pass it around, 2 bottles of beer on the wall.

2 bottles of beer on the wall, 2 bottles of beer.
Take one down and pass it around, 1 bottle of beer on the wall.

1 bottle of beer on the wall, 1 bottle of beer.
Take one down and pass it around, no more bottles of beer on the wall.

No more bottles of beer on the wall, no more bottles of beer.
Go to the store and buy some more, 10 bottles of beer on the wall.