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 F#

(Tail Recursion Call)

Date:06/22/09
Author:Simon Kang
URL:n/a
Comments:0
Info:n/a
Score: (2.75 in 8 votes)
let rec writeBeerSong n =
    let bottleString1 n1 =
        match n1 with
        | 0 -> "no more bottles of beer"
        | 1 -> "1 bottle of beer"
        | _ -> n1.ToString() + " bottles of beer"
    let bottleString2 n2 = 
        match n2 with
        | 0 -> "No more bottles of beer on the wall"
        | _ -> bottleString1 n2 + " on the wall"
    printfn "%s, %s" (bottleString2 n) (bottleString1 n)
    match n with
    | 0 ->  printf "Go to the store and buy some more,"
            printfn " 99 bottles of beer on the wall."
    | _ ->  printfn "Take one down and pass it around, %s on the wall.\n"
                (bottleString1 (n - 1))
            writeBeerSong (n - 1)

writeBeerSong 99

Download Source | Write Comment

Alternative Versions

VersionAuthorDateCommentsRate
Using list comprehensionJörn Rönnow02/01/093
Cleaner stillDon Syme12/07/060
Recursive implementationAlec Zorab07/04/090
lists and lambda'sKyle Eppley05/04/100

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: