Voting

Category

real language

Bookmarking

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

Language OCaml

(A little modification to the current one)

Date:01/28/06
Author:Philippe Wang
URL:http://mythoughts.free.fr/
Comments:1
Info:http://caml.inria.fr/
Score: (3.01 in 117 votes)
(* this is only a little modification of the current code by  Walter C. Reel III *)
(* in deed, I just made it be a little more ``Caml-looking'' *)

let bottles n =
  string_of_int n ^ " bottle" ^ (if n = 1 then "" else "s") ^ " of beer" in
let finale = function
    0 ->  "\nNo more bottles of beer on the wall!" 
  | n ->  ((bottles n) ^ " on the wall.\n\n") in
let round n =
  print_string ((bottles n) ^ " on the wall,\n");
  print_string ((bottles n) ^ ".\n");
  print_string "Take one down, pass it around.\n";
  print_string (finale (pred n)) in
let rec doit = function 
    0 -> ()
  | n -> round n; doit (pred n) in
doit 99;;

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
working with new versions, using printfDavid Baelde11/08/050
functional versionAnonymous04/20/050
version with recursive variant typePierre Etchemaïté11/18/051
historic versionPhilipp Winterberg04/20/050

Comments

>>  Frank Thieme said on 09/20/07 19:56:41

Frank Thieme Very nice...

0 -> "\nNo more bottles of beer on the wall!"

There should be another \n at the end of the line, IMHO.

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: