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

(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.84 in 32 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

VersionAuthorDateCommentsRate
functional versionAnonymous04/20/050
A little modification to the current onePhilippe Wang01/28/061
version with recursive variant typePierre Etchemaïté11/18/051
historic versionPhilipp Winterberg04/20/050

Comments

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: