Language F#
(Cleaner still)
Date: | 12/07/06 |
Author: | Don Syme |
URL: | n/a |
Comments: | 0 |
Info: | http://research.microsoft.com/fsharp |
Score: | (2.96 in 25 votes) |
#light open System open System.Text open System.Drawing open System.Windows.Forms let theBottleSong = let strSong = new StringBuilder() let append (s:string) = strSong.Append(s) |> ignore for i = 99 downto 0 do if (i = 0) then append("\nNo more bottles of beer on the wall, no more bottles of beer." + "\nGo to the store and buy some more, 99 bottles of beer on the wall.") else let x = i - 1 let plural = if (i = 1) then "" else "s" append (sprintf "\n%d bottle%s of beer on the wall, %d bottle%s" i plural i plural); append "\nTake one down and pass it around, "; match x with | 1 -> append "1 bottle " | 0 -> append " no more bottles " | _ -> append (sprintf "%d bottles of beer on the wall.\n" x) strSong.ToString() let form = new Form(Width=500, Height=420, Visible=true, TopMost=true, FormBorderStyle=FormBorderStyle.FixedSingle, Text="99 bottles of beer presented in F#") let textBox = new RichTextBox(Size=new Size(480, 350), Location=new Point(5, 5), Text=theBottleSong) form.Controls.Add(textBox) let btnClose = new Button(Location=new Point(408, 360), Text="Close") btnClose.Click.Add (fun _ -> form.Close()) form.Controls.Add(btnClose) [<STAThread>] do Application.Run(form)
Download Source | Write Comment
Alternative Versions
Version | Author | Date | Comments | Rate |
---|---|---|---|---|
Using list comprehension | Jörn Rönnow | 02/01/09 | 3 | |
Recursive implementation | Alec Zorab | 07/04/09 | 0 | |
Tail Recursion Call | Simon Kang | 06/22/09 | 0 | |
lists and lambda's | Kyle Eppley | 05/04/10 | 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