Language OCaml
(working with new versions, using printf)
Date: | 11/08/05 |
Author: | David Baelde |
URL: | http://perso.ens-lyon.fr/david.baelde |
Comments: | 0 |
Info: | http://caml.inria.fr/ocaml/index.en.html |
Score: | (3.85 in 33 votes) |
let bottles = function | 0 -> "no more bottles" | 1 -> "1 bottle" | n -> Printf.sprintf "%d bottles" n let rec song n = let current = bottles n in let next = bottles (n-1) in Printf.printf "%s of beer on the wall, %s of beer.\n" (String.capitalize current) current ; if n > 0 then begin Printf.printf "Take one down and pass it around, %s of beer on the wall.\n\n" next ; song (n-1) end else Printf.printf "Go to the store and buy some more, 99 bottles of beer on the wall.\n" let run = song 99
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
functional version | Anonymous | 04/20/05 | 0 | |
A little modification to the current one | Philippe Wang | 01/28/06 | 1 | |
version with recursive variant type | Pierre Etchemaïté | 11/18/05 | 1 | |
historic version | Philipp Winterberg | 04/20/05 | 0 |
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